[英]Python Selenium ID Tags change each time i refresh the page
I am currently trying to automate a data entry process.我目前正在尝试自动化数据输入过程。 Every time I refresh the page the ID tags change and make it impossible.
每次我刷新页面时,ID 标记都会更改并使其变得不可能。 I read that I can use CSS selectors or a possible xpath using tags that don't change.
我读到我可以使用 CSS 选择器或可能的 xpath 使用不会更改的标签。 It seems that only the ID tags are the problem.
似乎只有 ID 标签是问题所在。
Below is the HTML code for the button.下面是按钮的 HTML 代码。 Every time i try and use the CSS selector i got a no such element exception.
每次我尝试使用 CSS 选择器时,我都会遇到无此类元素异常。 I think I am doing it wrong.
我想我做错了。 Please help.
请帮忙。
<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>
Try this:尝试这个:
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()
The element gets wrapped in a WebDriverWait until it is interactable, in this case clickable元素被包裹在 WebDriverWait 中,直到它可以交互,在这种情况下是可点击的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.