Selenium:如何单击禁用的按钮
我通过 xpath 检查按钮可用性,因为按钮经常更改 css 类:
wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))
但程序无法找到并单击该按钮。 我不知道,我可以使用该方法来点击,所以也许你知道如何找到没有类/id 的buttun 的方法。
它应该等到按钮可单击并单击该按钮。 完整功能:
try:
wait = WebDriverWait(browser, 900)
ButtBuy = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))
except:
time.sleep(30)
browser.quit()
else:
ButtBuy.click()
wait = WebDriverWait(browser, 5)
ButtConfirm = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[8]/div/div/div[2]/button[2]')))
ButtConfirm.click()
我认为xpath不正确,但它是正确的,我通过xPath finder扩展在Firefox浏览器中粘贴xpath,也许扩展不正确生成的xpath。
按钮在指定时间变为可用。当按钮可用时,程序必须单击该按钮。
按钮的 HTML:
I check button availability by xpath because button often change css class:
wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))
But programm can`t find and click that button.
Idk, can I use that method to be clickable, so maybe you know method how to find buttun w/o class/id.
It should wait until button will be clickable and click the button.
full function:
try:
wait = WebDriverWait(browser, 900)
ButtBuy = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))
except:
time.sleep(30)
browser.quit()
else:
ButtBuy.click()
wait = WebDriverWait(browser, 5)
ButtConfirm = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[8]/div/div/div[2]/button[2]')))
ButtConfirm.click()
I think that xpath isn`t correct, but its correct, i paste xpath by xPath finder extension in Firefox browser, Maybe extension not correct generated xpath.
Button in the appointed time becomes available. And when the button becomes available, the program must click the button.
Html of the button:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML
禁用 属性存在意味着应该禁用该按钮,并且禁用按钮不可用且不可点击。
禁用属性通常设置为禁止用户单击按钮,直到满足其他条件(例如选择复选框等)。然后,JavaScript 可以删除禁用的值,并使按钮再次可单击。
根据元素
的 HTML,由于该元素已禁用< /em> 属性设置后您将无法单击/与其交互。
HTML
<button>
disabled AttributeThe disabled attribute when present implies that the button should be disabled and a disabled button is unusable and un-clickable.
The disabled attribute is generally set to refrain a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc). Then, a JavaScript could remove the disabled value, and make the button clickable again.
As per the HTML of the element
As the element is having the disabled attribute set you won't be able to click/interact with it.