简体   繁体   English

如何让 Selenium 点击这个按钮?

[英]How do I make Selenium click on this button?

Here's my code:这是我的代码:

<ul class="Buttons--stackOnMobile">
    <li class="col">
        <button class="Button">Sign In</button>
    </li>
    <li class="col col--secondary">
        <a class="Button Button--alt" href="/account/create">Create an Account</a>
    </li>
    <li class="col hide">
        <button class="Button">Sign In</button>
    </li>
</ul>

I'm trying to make selenium click on Sign in button.我正在尝试让 selenium 单击登录按钮。

I'm coding in Python 3.6.我在 Python 3.6 中编码。

There are two buttons are present with the same xpath.有两个按钮具有相同的 xpath。

if you want to click first button then use below code如果你想点击第一个按钮然后使用下面的代码

wait = WebDriverWait(browser, 10)
button= wait.until(EC.element_to_be_clickable((By.XPATH,'(//button[@class="Button"])[1]')))
button.click()

if you want to click the second button then use below code如果你想点击第二个按钮然后使用下面的代码

  wait = WebDriverWait(browser, 10)
    button= wait.until(EC.element_to_be_clickable((By.XPATH,'(//button[@class="Button"])[2]')))
    button.click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM