我目前正在研究一段代码,并使用纪录片完成了很多阅读并查看了很多示例,但仍然无法修复我的错误。我正在使用Python和Selenium Webdriver。Python和Selenium Click和“TypeError:字符串索引必须是整数”
下面是问题:我试图从使用Javascript的HTML页面中提取图像。一旦我使用selenium webdriver,就会显示函数调用的结果(在firefox中),但是我无法点击页面底部的数字以进入第3或第4页。
这里是我有问题的HTML代码:
<div class="pagebook" data-reactid=".1.0.2.0"><div style="display:none;" data-reactid=".1.0.2.0.0"></div><div class="active" data-reactid=".1.0.2.0.1:$0">1</div><div class="" data-reactid=".1.0.2.0.1:$1">2</div><div class="" data-reactid=".1.0.2.0.1:$2">3</div><div class="" data-reactid=".1.0.2.0.1:$3">4</div><div class="" data-reactid=".1.0.2.0.1:$4">5</div><div class="" dat<div class="next" style="margin-right:20px;" data-reactid=".1.0.2.0.$6">►</div></div>
我使用XPath能力这样做的呼叫:browser.find_element_by_xpath('//div[@data-reactid=".1.0.2.0.1:$2"]').click()
我第一次这样做,它的工作了几下,然后将其给了我一个错误,我再也不能使用它了。错误是:
File "C:\Python27\Lib\site-packages\selenium-2.49.2-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 111, in check_response
message = value["value"]["message"]
TypeError: string indices must be integers
这里是我使用的代码:
browser = webdriver.Firefox()
browser.implicitly_wait(5) #backup wait of 5 seconds just in case
browser.get(url2)
browser.find_element_by_xpath('//div[@data-reactid=".1.0.2.0.1:$2"]').click()
我所寻找的帮助:
- 错误
- 使用不同的功能用于点击
欣赏它!
它是**满**错误信息? – furas
@furas是msg的主要错误:“TypeError:字符串索引必须是整数”。我应该包含整个Traceback吗? – BigMike