2

Below is my HTML snippet and code I tried. I need to Click the Integrated Consoles menu item. I tried like below, But nothing happens and no error as well. Kindly help me to select the Specific Menu Item using the text inside the tag.

driver.find_element_by_xpath(".//td[contains text(),'Integrated Consoles']").click()

HTMl sample Snippet

<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;Integrated Consoles&nbsp;</td>
<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;System Information&nbsp;</td>
<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;More Tools&nbsp;</td>
3
  • 3
    can you change it to .//td[contains(text(),'Integrated Consoles')] and try Commented Jan 20, 2017 at 7:45
  • @NarendraRajput Worked. Thanks! Commented Jan 20, 2017 at 8:10
  • You should use normalize-space which trims leading and trailing spaces as well as reduce in between spaces to a single space. normalize-space(text(),'Integrated Consoles'). This way your xpath will get exact text instead of text like 'Newer Integrated Consoles etc'. stackoverflow.com/questions/11776910/… Commented Jan 20, 2017 at 8:21

1 Answer 1

1

Parentheses () are missing inside your contains method just enclose like below and try -

driver.find_element_by_xpath(".//td[contains(text(),'Integrated Consoles')]").click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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