首页 > 编程语言 > 详细

【selenium+python】关于使用selenium时的几个问题1

时间:2018-07-23 16:53:23      阅读:308      评论:0      收藏:0      [点我收藏+]

问题:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

原因:提示时没有添加到PATH环境变量,找不到webdriver

解决:win10下曾经把chromedriver所在目录添加到PATH环境变量,但是仍然报相同错误,经搜索,发现把chromedriver.exe放到和python脚本相同的目录下即可运行成功!

问题:TypeError: ‘WebElement‘ object is not iterable

原因:选择多个HTML页面元素的时候应该用方法的复数

解决:改用find_elements_by_tag_name,这里element有s

问题:AttributeError: ‘WebElement‘ object has no attribute ‘sendkeys‘

原因:代码里写了sendkeys,但是没有这个方法(实际是send_keys)

解决:把sendkeys改为send_keys(这个问题纯属粗心= =)

背景:在使用selenium进行爬虫的时候,需要输入关键字搜索,但是就出现了打开网页,输入关键字后抛出异常的情况。

问题:打开了网页后,抛异常,然后浏览器自动关闭

原因:经调试发现抛异常的位置在:

WebDriverWait(driver,15).until(

                    EC.title_contains(unicode(to_city))

                )

这里的意思是等待搜索结果页加载出包含关键字的网页才继续下一步,但是由于上一步输入to_city值的时候意外点到其他城市名,导致这一步抛出异常无法继续

 

【selenium+python】关于使用selenium时的几个问题1

原文:https://www.cnblogs.com/HAHACHANGEFROMNOW/p/9355421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!