0

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();
2
  • 2
    Your question is unclear. Commented Nov 4, 2013 at 16:16
  • Post your question with clear code and example. Commented Nov 4, 2013 at 17:44

1 Answer 1

1

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:

  • Try avoid using div[6], tr[12], use meaningful things instead of index
  • Don't use yui-gen0 if it's auto-generated
  • Keep HTML ids unique, like id="ItemM". If they are unique, use them directly

I'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();
Sign up to request clarification or add additional context in comments.

1 Comment

@khris: Do you have any feedback on this? Did it work for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.