简体   繁体   English

Python Selenium 每次刷新页面时ID标签都会改变

[英]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.

相关问题 使用 selenium python 加载每个页面的时间 - Loading time of each page with selenium python 每次页面加载时 ID 更改时,如何单击 Python Selenium 的复选框? - How to click check box with Python Selenium when ID changes each time the page loads? 带有硒的python每次都会擦除我所有的excel数据,我只有最后一个表页表 - python with selenium erase all my excel data each time and I just have the last table page table 尝试通过 selenium python 输入框 select 但每次我重新加载页面时元素中的“id”都会更改 - Trying to select an input box through selenium python but the 'id' in the element changes every time I reload the page Python Selenium Chrome-如果第一次加载页面的时间过长,如何刷新页面 - Python Selenium Chrome - How to refresh a page if it takes too long to load the page for the first time 刷新页面直到 Python Selenium 中的值发生变化 - Refresh page until value changes in Python Selenium 每次刷新我的html页面时如何刷新python文件? - How to refresh python file every time I refresh my html page? 更改ID3标签Python 2.7 - Change ID3 Tags Python 2.7 使用 Selenium python,在等待隐藏 btn 出现并可点击时是否需要刷新页面? - With Selenium python, do I need to refresh the page when waiting for hidden btn to appear and be clickable? 使用Selenium和python提取没有任何类和ID的div标签 - Extracting div tags without any class and id using selenium and python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM