PoweredByCoffee PoweredByCoffee - 8 days ago 7
Python Question

XPath location if parent contains

Struggling a bit trying to figure out what's going on with my XPath syntax here. Trying to locate an element to click based on the text of the parent.

I want to rotate through

<tr>
tags and and click a button if that tr contains specific text.

I've tried:

element = WebDriver.find_elements_by_xpath("//tr[contains(text(), 'This Text')]/td[@class='cell-to-click']")


Common stuff is all covered. The details are correct and loaded on the WebDriver etc... I can read the data parsing with BeautifulSoup so it is there. Just struggling to locate it to click.

I'd appreciate any pointers on this I'm out of things to try.

Answer

Try //tr[contains(., 'This Text')]/td[@class='cell-to-click'] instead. tr elements usually don't have text nodes as children.

Comments