我知道以前曾问过这个问题,但以前的答案都没有帮助我。 我需要抓取一个通过选择此页面上的单选按钮之一生成的表格-https://www.oeko-tex.com/en/business/oeko_tex_certified_products/oeko_tex_certified_products.html
到目前为止,我的代码-
driver.get("https://www.oeko-tex.com/en/business/oeko_tex_certified_products/oeko_tex_certified_products.html")
time.sleep(2)
radio = driver.find_element_by_xpath(".//input[@type='radio' and @value='step']")
time.sleep(2)
radio.click()
据我了解,xpath在这里无效。 任何帮助将不胜感激。预先感谢。
答案 0 :(得分:1)
您使用的xpath有效。问题是单选按钮在框架内。因此,您需要切换到该框架,然后搜索该元素。
在搜索单选按钮之前添加以下内容:
driver.switch_to.frame(driver.find_element_by_tag_name('iframe'))
我也建议使用webdriverwait
而不是time.sleep
通话。