51Testing软件测试论坛

标题: 从父找向子的方法,找不到click()方法 [打印本页]

作者: hjy233333    时间: 2018-3-29 10:48
标题: 从父找向子的方法,找不到click()方法
driver.find_element_by_id("radDiv").find_elements_by_xpath('//input[@value="NoR"]').click()
报错Traceback(most recent call last):
File"C:/Users/candy.hou/PycharmProjects/PyProjects/Demo/package/WebDriverStudy.py",line 41, in <module>
    driver.find_element_by_id("radDiv").find_elements_by_xpath('//input[@value="NoR"]').click()
AttributeError: 'list' object has no attribute 'click'
HTML:
<divid = "radDiv">
<tr>
<td>
Select RadioY<input type="radio" name="current"value="YesR"/>
</td>
<td>
Select RadioN<input type="radio" name="current"value="NoR"/>
</td>
</tr>
</div>


在学课程
分层自动化测试(UI+接口)--从入门到放弃
http://www.atstudy.com/course/71


作者: 清晨一缕阳光    时间: 2018-3-29 11:36
driver.find_element_by_id("radDiv").find_elements_by_xpath('//input[@value="NoR"]')这个代码执行完之后,返回的对象是多个,再使用click方法的时候,程序不知道点击的是哪个元素,所以报错。
作者: 学掌门网校    时间: 2018-3-29 17:06
报错信息是AttributeError: 'list' object has no attribute 'click';
结合你的代码
driver.find_element_by_id("radDiv").find_elements_by_xpath('//input[@value="NoR"]').click()
查找子元素时你使用了find_elements_by_xpath()这个函数会返回一个数组,你把这个改为find_element_by_xpath就可以了。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2