[英]Python Selenium ID Tags change each time i refresh the page
我目前正在嘗試自動化數據輸入過程。 每次我刷新頁面時,ID 標記都會更改並使其變得不可能。 我讀到我可以使用 CSS 選擇器或可能的 xpath 使用不會更改的標簽。 似乎只有 ID 標簽是問題所在。
下面是按鈕的 HTML 代碼。 每次我嘗試使用 CSS 選擇器時,我都會遇到無此類元素異常。 我想我做錯了。 請幫忙。
<button type="button" class="dark button secondary" data-automation-id=
"btn-footer-save" data-dojo-attach-event="onclick:saveAndStayPressed"
data-qbo-bind="visible:shouldShowSaveAndStayButton" style>Save</button>
嘗試這個:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = new WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Save')]"))).click()
元素被包裹在 WebDriverWait 中,直到它可以交互,在這種情況下是可點擊的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.