selenium中'WebElement' object is not iterable报错问题
来源:互联网 发布:表白app源码 编辑:程序博客网 时间:2024/06/05 02:41
checkbox.html源码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-
equiv
=
"content-type"
content
=
"text/html;charset=utf-8"
/
>
/
title>
type
=
"text/javascript"
async
=
"
"src="
https:
/
/
ajax.googleapis.com
/
ajax
/
libs
/
jquery
/
1.9
.
1
/
jquery.
min
.js"><</CODE>
/script>
=
"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css"
rel
=
"stylesheet"
/
>
=
"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"
><</CODE>
/script>
<</CODE>
/head>
checkbox<</CODE>
/h3>
class
=
"well"
>
class
=
"form-horizontal"
>
class
=
"control-group"
>
class
=
"control-label"
for
=
"c1"
>checkbox1<</CODE>
/
label>
class
=
"controls"
>
<</CODE>
inputtype
=
"checkbox"
id
=
"c1"
/
>
<</CODE>
/div>
<</CODE>
/div>
class
=
"control-group"
>
class
=
"control-label"
for
=
"c2"
>checkbox2<</CODE>
/
label>
class
=
"controls"
>
<</CODE>
inputtype
=
"checkbox"
id
=
"c2"
/
>
<</CODE>
/div>
<</CODE>
/div>
class
=
"control-group"
>
class
=
"control-label"
for
=
"c3"
>checkbox3<</CODE>
/
label>
class
=
"controls"
>
<</CODE>
inputtype
=
"checkbox"
id
=
"c3"
/
>
<</CODE>
/div>
<</CODE>
/div>
class
=
"control-group"
>
class
=
"control-label"
for
=
"r"
>radio<</CODE>
/
label>
class
=
"controls"
>
<</CODE>
inputtype
=
"radio"
id
=
"r"
/
>
<</CODE>
/div>
<</CODE>
/div>
<</CODE>
/form>
<</CODE>
/div>
<</CODE>
/body>
<</CODE>
/html>
Python代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
#coding=utf-8
from
selenium
import
webdriver
import
time
import
os
dr
=
webdriver.Firefox()
file_path
=
'file:///'
+
os.path.abspath(
'checkbox.html'
)
dr.get(file_path)
# 选择所有的checkbox并全部勾上
checkboxes
=
dr.find_element_by_css_selector(
'input[type=checkbox]'
)
for
check
in
checkboxes:
check.click()
time.sleep(
1
)
# 打印当前页面上有多少个checkbox
dr.quit()
报错内容:TypeError: 'WebElement' object isnot iterable
解决办法:
checkboxes
=
dr.find_element_by_css_selector(
'input[type=checkbox]'
)
改为:
checkboxes
=
dr.find_elements_by_css_selector(
'input[type=checkbox]'
)
或者:input1 = dr.find_elements_by_tag_name('input')
注意:因为是定位一组元素,而不是单个元素,在书写时要特别注意;
阅读全文
0 0
- selenium中'WebElement' object is not iterable报错问题
- “'WebElement' object is not iterable”
- scrapy domz报错TypeError: 'float' object is not iterable
- Django 报错 'AnonymousUser' object is not iterable 的解决办法
- Django出现报错'AnonymousUser' object is not iterable
- 'classobj' object is not iterable ?
- 'NoneType' object is not iterable
- python object is not iterable
- python框架Scrapy报错TypeError: 'float' object is not iterable解决
- python mysql 插入数据报错 Failed processing format-parameters; 'int' object is not iterable
- Scrapy使用shell命令报错scrape shell TypeError: 'float' object is not iterable
- python TypeError: 'int' object is not iterable
- TypeError: ‘NoneType’ object is not iterable
- python 'float'object is not iterable
- TypeError: 'NoneType' object is not iterable
- 启动robot framework报'NoneType' object is not iterable的原因
- 【Python】python "TypeError: 'NoneType' object is not iterable"错误分析
- Python出现TypeError: 'NoneType' object is not iterable
- 不使用库函数复制字符串
- wordpress 禁用gravatar使用本地头像提高网页打开速度
- version `GLIBCXX_3.4.21' not found 解决办法
- 消息队列的使用场景
- Jetson TX2使用系列(1)--开发环境安装
- selenium中'WebElement' object is not iterable报错问题
- 如何走向真正的人工智能?
- 贪心算法——删数问题
- Manifest merger failed with multiple errors, see logs
- Java算法—选择排序
- Go char 与string 的拼接 数据加密
- 数据中心的敏捷运维之路
- solr定时实时重建索引和增量更新
- 智能小车十二《整合软硬件制造蓝牙小车》