如何使用Selenium和Python选择单选按钮 [英] How to select radio button with Selenium and Python

查看:271
本文介绍了如何使用Selenium和Python选择单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择单选按钮"Hitter".有人可以帮忙吗?我已经尝试了很多不同的方法,但是始终收到消息:元素不可见".

I am trying to select the radio button "Hitter". Could anyone help? I've tried a lot of different things, but keep getting "Message: element not visible".

谢谢!

推荐答案

有多种方法可以找到无线电input,以下是使用find_element_by_id()的一种方法:

There are multiple ways to locate the radio input, here is the one using find_element_by_id():

radio = driver.find_element_by_id("ContentPlaceHolder1_HitterRadioButton")
radio.click()

或者,如果您对这种方法有疑问,可以通过javascript模拟一次点击:

Or, if you have problems with this approach, you can simulate a click via javascript:

radio = driver.find_element_by_id("ContentPlaceHolder1_HitterRadioButton")
driver.execute_script("arguments[0].click();", radio)

这篇关于如何使用Selenium和Python选择单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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