Selenium:如何单击禁用的按钮

发布于 2025-01-16 16:20:09 字数 995 浏览 4 评论 0原文

我通过 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:

按钮的 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:

html code of button

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2025-01-23 16:20:09

HTML

禁用 属性存在意味着应该禁用该按钮,并且禁用按钮不可用不可点击

禁用属性通常设置为禁止用户单击按钮,直到满足其他条件(例如选择复选框等)。然后,JavaScript 可以删除禁用的值,并使按钮再次可单击。

根据元素

HTML

的 HTML,由于该元素已禁用< /em> 属性设置后您将无法单击/与其交互。

HTML <button> disabled Attribute

The 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

HTML

As the element is having the disabled attribute set you won't be able to click/interact with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文