Reputation: 4999
I need to choose element APPLICATION from list on UI. html code of this element (in html I have 10 such elements)is:
<tr id="4676856" class="menuItem" orientation="vertical" collectionid="tr4" radioid="12">
<td id="ItemL" class="left" data-click="[["runScript",["switchApplication('myapp')"]]]" data-ctl="nav">
<div class="menuRB"/>
</td>
<td id="ItemM" class="middleBack" tabindex="0" data-click="[["runScript",["switchApplication('myapp')"]]]" data-ctl="nav">**APPLICATION**</td>
<td id="ItemR" class="rightEdge" data-click="[["runScript",["switchApplication('myapp')"]]]" data-ctl="nav"/>
I have never worked with such script, how can I find such element using selenium webdriver?
I have tried
driver.findElement(By.xpath(".//*[@id='yui-gen0']/div[6]/table/tbody/tr[12]/td[1]")).click();
Upvotes: 0
Views: 1196
Reputation: 32885
Please show HTML code that matches your XPaths (where is yui-gen0
and such?)
From the info you provided, few issues you might want to avoid:
yui-gen0
if it's auto-generatedid="ItemM"
. If they are unique, use them directlyI'd suggest try the following (we need you to show more HTML in order to avoid using div[6], tr[12]):
// find by text '**APPLICATION**'
driver.findElement(By.xpath(".//*[@id='yui-gen0']/div[6]/table/tbody/tr[12]/td[text()='**APPLICATION**']")).click();
// find by class name (if it's the only one)
driver.findElement(By.xpath(".//*[@id='yui-gen0']/div[6]/table/tbody/tr[12]/td[@class='middleBack']")).click();
// find by class name (if there are others)
driver.findElement(By.xpath(".//*[@id='yui-gen0']/div[6]/table/tbody/tr[12]/td[contains(@class, 'middleBack')]")).click();
// find by id, which should be unique, if it's not, your HTML is bad
driver.findElement(By.xpath(".//*[@id='ItemM']")).click();
Upvotes: 1