Python:find_element_by_css_selector [英] Python: find_element_by_css_selector

查看:655
本文介绍了Python:find_element_by_css_selector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用网络驱动程序单击登录按钮

I am trying to click the login button with webdriver

<a class="login-btn" href="javascript:;" data-bind="click:loginSection.loginClick">
    <span class="btn-text">Login</span>
</a>

我的代码:

submit=driver.find_element_by_css_selector('a.login-btn').click()

或尝试以下代码:

submit=driver.find_element_by_class_name('login-btn').click()

这些都不起作用,需要一些建议.预先感谢

Neither of these is working, need some advice. Thanks in advance

错误:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"a.login-btn"}

推荐答案

要单击登录按钮,可以使用以下任一代码行:

To click on the Login button you can use either of the the following line of code :

  • LinkText :

driver.find_element_by_link_text("Login").click()

  • CssSelector :

    driver.find_element_by_css_selector("a.login-btn > span.btn-text").click()
    

  • 使用 CssSelector 更加细化,您还可以使用以下代码行:

  • Getting more granular with the CssSelector you can also use the following line of code :

    driver.find_element_by_css_selector("a.login-btn[data-bind='click:loginSection.loginClick'] > span.btn-text").click()
    

  • 更新: 看到 NoSuchElementException 时,您可以检查

    Update : As you are seeing NoSuchElementException you can check this discussion

    这篇关于Python:find_element_by_css_selector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆