PoweredByCoffee PoweredByCoffee - 1 year ago 93
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

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download