简体   繁体   中英

selenium following element python

I'm using selenium with python. I have some element that is a checkbox, and I want to click on it. My problem is with getting that element, I have only the text In my case <td>xxxxx</td> and I want to get the element above it (the previous element, he is not is father, they are only adjacent) I tried this:

driver.find_element_by_xpath("//input[@type='checkbox']/following::td[text()='xxxxx']").click()

but it didn't work.

在此处输入图片说明

You can navigate from td with following xpath

driver.find_element_by_xpath("//td[text()='xxxxx']/preceding-sibling::td[1]/input[@type='checkbox']").click()

or you can try with parent tag and navigate nth td which has input tag like

driver.find_element_by_xpath("//td[text()='xxxxx']/parent::tr/td[1]/input[@type='checkbox']").click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM