[英]How to find element without id selenium python
如果沒有 id 或元素有動態 id,則使用 XPATH。 使用 class 並不理想,因為 class 可能會被許多其他元素重用。
在這種情況下,使用這個 XPATH: //summary[.//span[contains(text(),"Add file")]]
最佳實踐:使用流利的等待
WebDriverWait(driver, 15).until(
EC.visibility_of_element_located(
(By.XPATH, '//summary[.//span[contains(text(),"Add file")]]')
))
閱讀有關顯式/流暢等待的文檔: https://selenium-python.readthedocs.io/waits.html#explicit-waits
你可以試試driver.find_element_by_xpath("[xpath goes here]")
如果你想了解更多,這里是定位元素的官方文檔。
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.