单击带有 selenium-webdriver 的复选框 [英] Click a checkbox with selenium-webdriver

查看:36
本文介绍了单击带有 selenium-webdriver 的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tumblr 测试我的应用程序,我必须在执行程序时登录和退出.这样做时,我无法单击不断弹出的复选框.如何在python中使用selenium-webriver来点击它?

I'm testing my app with tumblr and I have to log in and out as I go through procedures. While doing so, I'm having trouble clicking a checkbox that keeps popping up. How can I use selenium-webriver in python to click it?

我已经尝试选择 xpaths、...by_ids 和 by_classes,但它们不起作用,所以现在我尝试使用鼠标的坐标来物理单击该项目.(这是在 tumblr 登录页面,仅供参考)

I've tried selecting xpaths, ...by_ids, and by_classes, they won't work, so now I'm trying to use the mouse's coordinates to physically click the item. (This is on the tumblr login page, fyi)

以上是我要选择的项目的 html.

Above is the html of the item I'm trying to select.

()我有以下选择器:

#checkbox = driver.find_element_by_id("recaptcha-anchor")
#checkbox = driver.find_element_by_id("g-recaptcha") 
#driver.find_element_by_xpath("//*[@id='recaptcha-token']")
#driver.find_element_by_css_selector("#recaptcha-anchor")
#driver.find_element_by_xpath("//*[@id='recaptcha-anchor']")
#driver.find_element_by_id("recaptcha-token").click()
#driver.find_element_by_class_name('rc-anchor-center-container')
#checkbox = driver.find_element_by_id("recaptcha-anchor")

推荐答案

这是一个适用于我的 Java 简单示例:

Here is a simple example that works for me in Java:

driver.findElement(By.id("checkbox_id")).click();

在 Python 中,它似乎是:

In Python, it seems to be:

driver.find_element_by_id("checkbox_id").click()

这篇关于单击带有 selenium-webdriver 的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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