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
    can you change it to `.//td[contains(text(),'Integrated Consoles')]` and try – NarendraR Jan 20 '17 at 07:45
  • @NarendraRajput Worked. Thanks! –  Jan 20 '17 at 08: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'. http://stackoverflow.com/questions/11776910/xpath-expression-to-remove-whitespace – Grasshopper Jan 20 '17 at 08:21

1 Answers1

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()
NarendraR
  • 7,577
  • 10
  • 44
  • 82