2

This HTML code has menu of targets and you need to select one target. One of these targets is ANY TARGET to continue process.

<tr id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0" class=" iceRowSelMouseOver" tabindex="0" onmouseover="this.className=' iceRowSelMouseOver';" onmouseout="Ice.enableTxtSelection(document.body); this.className='iceDatTblRow1 selectable-rowRow1 iceRowSel'" onmousedown="return Ice.preventTextSelection(event);" ondblclick="Ice.registerDblClick(this);" onclick="Ice.registerClick(this,'mainForm:nav-panel-tab-set:0:trigger-selectTableclick_row','mainForm:nav-panel-tab-set:0:trigger-selectTableclick_count','0','mainForm',200,true,event,false,'mainForm:nav-panel-tab-set:0:trigger-selectTablesel_rows','');">
<td class="iceDatTblCol1 selectable-rowCol1" scope="row">
<a id="mainForm:nav-panel-tab-set:0:trigger-selectTable_idx_0" class="iceHdnLnk" onfocus="return Ice.tblRowFocus(this, false);" onblur="return Ice.tblRowBlur(this);" href="#">
<img alt="" src="/ice/xmlhttp/css/xp/css-images/spacer.gif"/>
</a>
<span id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1417" class="iceOutTxt">ANY TARGET</span>
</td>
<td class="iceDatTblCol2 selectable-rowCol2">
<span id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1419" class="iceOutTxt select-icon">ยป</span>
</td>
</tr>

How can I reach the ANY TARGET to click on >> to add using XPATH?

Extra Information:

The previous code is for sub window to add target. the main window code is:

<tr class="icePnlGrdRow1 settings-tableRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1305-2-0" class="icePnlGrdCol1 settings-tableCol1">
<table id="mainForm:nav-panel-tab-set:0:j_idt1326" class="icePnlGrd settingsLabel">
<tbody>
<tr class="icePnlGrdRow1 settingsLabelRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1326-0-0" class="icePnlGrdCol1 settingsLabelCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1327" class="iceOutTxt label">Target</span>
</td>
</tr>
<tr class="icePnlGrdRow2 settingsLabelRow2">
<td id="mainForm:nav-panel-tab-set:0:j_idt1326-1-0" class="icePnlGrdCol1 settingsLabelCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1328" class="iceOutTxt sidenote">Target or group</span>
</td>
</tr>
</tbody>
</table>
</td>
<td id="mainForm:nav-panel-tab-set:0:j_idt1305-2-1" class="icePnlGrdCol2 settings-tableCol2">
<table id="mainForm:nav-panel-tab-set:0:j_idt1329" class="icePnlGrd search">
<tbody>
<tr class="icePnlGrdRow1 searchRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1329-0-0" class="icePnlGrdCol1 searchCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1330" class="iceOutTxt"/>
</td>
<td id="mainForm:nav-panel-tab-set:0:j_idt1329-0-1" class="icePnlGrdCol2 searchCol2">
<input id="mainForm:nav-panel-tab-set:0:j_idt1331" class="iceCmdBtn" type="image" src="/ice/img/search-icon.png" onfocus="setFocus(this.id);" onclick="iceSubmitPartial(form, this, event);return false;" onblur="setFocus('');" name="mainForm:nav-panel-tab-set:0:j_idt1331"/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>

I used ID to click on the targets to open the sub window

//*[@id='mainForm:nav-panel-tab-set:0:j_idt1331']

However, I did not get any response to add any target to my main window either I used the solutions you mentioned.

Yamur
  • 339
  • 6
  • 20

2 Answers2

0

You can reach the span containing "ANY TARGET":

//span[text() = "ANY TARGET"]

You can extend this to reach the span containing ">>" in the td immediately following the td that contains "ANY TARGET":

//td[span[text() = "ANY TARGET"]]/following-sibling::td[1]/span[text() = ">>"]
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • @ kjhughes Thank you, but I got this problem `SyntaxError: Non-ASCII character '\xc2' in file`. This problem pointed on ">>" โ€“ Yamur Aug 04 '14 at 14:55
  • I believe that this new '\xc2' error is a **separate issue**. Find and eliminate the special character, or try putting "# coding=utf-8" at the top of your python source to [*define the source encoding*](http://legacy.python.org/dev/peps/pep-0263/). See also this [SO question and answers](http://stackoverflow.com/q/1342000/290085) or @alecxe's fine answer [here](http://stackoverflow.com/a/18078860/290085). โ€“ kjhughes Aug 04 '14 at 16:03
  • Thank you it's work well. Finally :). This code is correct `//td[span[text() = "ANY TARGET"]]/following-sibling::td[1]/span[text() = ">>"]` โ€“ Yamur Aug 05 '14 at 11:47
0

Try to focus on the first TD and then click on the Span element.

            IWebElement td = browser_drive.FindElement(By.Id("mainForm:nav-panel-tab-set:0:trigger-selectTable:0")).FindElements(By.TagName("td"))[0];
            IWebElement anytext = td.FindElement(By.Id("mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1417"));

            OpenQA.Selenium.Interactions.Actions act = new OpenQA.Selenium.Interactions.Actions(browser_drive);
            act.MoveToElement(td).Click(anytext);

(Coded using C#, there must be an alternative. Pseudo code, not complied)

Sham
  • 830
  • 9
  • 27