[英]How to find element without id selenium python
If no id or the element has dynamic id, use XPATH.如果没有 id 或元素有动态 id,则使用 XPATH。 Using class is not ideal, since the class will possibly reused by many other elements.
使用 class 并不理想,因为 class 可能会被许多其他元素重用。
In this case, use this XPATH: //summary[.//span[contains(text(),"Add file")]]
在这种情况下,使用这个 XPATH:
//summary[.//span[contains(text(),"Add file")]]
Best practice: use fluent wait最佳实践:使用流利的等待
WebDriverWait(driver, 15).until(
EC.visibility_of_element_located(
(By.XPATH, '//summary[.//span[contains(text(),"Add file")]]')
))
Read docs about explicit/fluent wait: https://selenium-python.readthedocs.io/waits.html#explicit-waits阅读有关显式/流畅等待的文档: https://selenium-python.readthedocs.io/waits.html#explicit-waits
You could try driver.find_element_by_xpath("[xpath goes here]")
你可以试试
driver.find_element_by_xpath("[xpath goes here]")
If you want to read more, here are the official docs for locating elements.如果你想了解更多,这里是定位元素的官方文档。
from selenium import webdirver
#define your executable path
browser = webdriver.Chrome(executable path=" ")
browser.get("**")
browser.find_element_by_xpath("put your copied xpath here")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.