无法在Python中选择带有硒的单选按钮 [英] Unable to select radio button with selenium in Python

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

问题描述

我正在尝试从此选择使用Python Selenium的房间数"字段网址.

我当前的代码是:

inputBHK = driver.find_element_by_id("No_of_Rooms_newpap")
input1BHK = driver.find_element_by_id("No_of_Rooms1")
ActionChains(driver).click(inputBHK).click(input1BHK).perform()

除了通常的导入和初始化. 引发的异常是:

Apart from the usual import and the Initialization. The exception Raised is:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: u'Offset within       
element cannot be scrolled into view: (0, 0): [object HTMLInputElement]' ; Stacktrace: 

关于如何进行的任何想法?

Any ideas on how to proceed?

推荐答案

尝试在2次点击事件之间等待,此网站的实施看起来比较棘手且缓慢 http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

try to wait between the 2 click events, the implementation of this site looks like tricky and slow http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

好的,我发现了一些问题,下拉菜单存在一些问题,例如在本网站中,它们使用隐藏的单选按钮,因此,我们将单击包含单选按钮的标签(而不是单击它)也适用于span元素,而不是单击它包含文本,如果您愿意的话,可以通过text()选择

edit: OK I found something, there is some problems with tricky drop down list like in this website, they use hidden radio button, so instead of click it we will click on the label which contains the radio button (it works also on the span element which contains the text, if you prefer select by text())

from selenium import webdriver

URL = 'http://kolkata.quikr.com/post-classifieds-ads/?postadcategoryid=971'

driver = webdriver.Firefox()
driver.get(URL)

inputBHK = driver.find_element_by_id("No_of_Rooms_newpap")
inputBHK.click()

container = driver.find_element_by_id("No_of_Rooms_l4Attr_RadioBox_div")
input1BHK = container.find_element_by_xpath(".//label[1]")
input1BHK.click()

这篇关于无法在Python中选择带有硒的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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