selenium调用Firefox和Chrome需要注意的一些问题,和出现的报错selenium:expected [object undefined] undefined to be a string
在高版本selenium下如:selenium3.4.3
1.高版本的selenium需要浏览器安装一些补丁驱动
Firefox:geckodriver
下载网址:http://download.csdn.net/detail/ztzy520/9725887 或https://github.com/mozilla/geckodriver/release
如:geckodriver-v0.14.0-win32
Chrome:chromedriver
下载网址:http://chromedriver.storage.googleapis.com/index.html
如:http://chromedriver.storage.googleapis.com/index.html?path=2.30/下
版本:chromedriver_win32.zip
2.直接将geckodriver和chromedriver放到浏览器的目录下
如geckodriver放到路径 C:\Program Files (x86)\Mozilla Firefox
如chromedriver放到路径 C:\Program Files (x86)\Google\Chrome\Application
3.调用方式
#方式一:设置火狐浏览器驱动(使用低于53.0版本火狐,如52.0.2,不然会报错selenium:expected [object undefined] undefined to be a string)
driver = webdriver.Firefox()
# 方式二:设置谷歌浏览器驱动
chromedriver = "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
4.具体测试代码(demo1.py):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import os
#=====================================================================
# 方式一:设置火狐浏览器驱动
driver = webdriver.Firefox()
#=====================================================================
# 方式二:设置谷歌浏览器驱动
#chromedriver = "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe"
#os.environ["webdriver.chrome.driver"] = chromedriver
#driver = webdriver.Chrome(chromedriver)
#=====================================================================
driver.get("http://www.baidu.com")
assert u"百度" in driver.title
elem = driver.find_element_by_name("wd")
elem.clear()
elem.send_keys(u"网络爬虫")
elem.send_keys(Keys.RETURN)
time.sleep(3)
assert u"网络爬虫." not in driver.page_source
driver.close()
注释:要解决调用火狐是出现"selenium:expected [object undefined] undefined to be a string"问题,需要将火狐的版本降低到53.0以下,如
52.0.2
selenium调用Firefox和Chrome需要注意的一些问题,和出现的报错selenium:expected [object undefined] undefined to be a string的更多相关文章
- robotframework执行用例时,报错selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinl
在用robotframework编写移动端测试用例(用chrome浏览器模拟手机浏览器),执行用例时, 报错selenium.common.exceptions.WebDriverException: ...
- Selenium click不生效 报错selenium.common.exceptions.InvalidArgumentException
记录在使用selenium过程中踩的坑------ 在使用selenium时,用click点击网站弹出的文件上传框的"上传文件"按钮不生效,报错selenium.common.ex ...
- python中使用selenium调用Firefox缺少geckodriver解决方法
from selenium import webdriver driver=webdriver.Firefox() 会报错 解决方法: 因为缺少geckodriver.exe,先到https://gi ...
- python+selenium遇到元素定位不到的问题,顺便记录一下自己这次的错误(报错selenium.common.exceptions.NoSuchElementException)
今天在写selenium一个发送邮件脚本时,遇到一些没有找到页面元素的错误.经过自己反复调试,找原因百度,终于解决了.简单总结一下吧,原因有以下几点: 一:Frame控件嵌套,.Frame/Ifram ...
- windows下使用selenium报错selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH
问题 :执行程序代码报错: WebDriverException:Message:'geckodriver'executable needs to be in Path 或者 selenium.com ...
- python无法启动火狐浏览器且报错“selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities”
安装了python2,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'gecko ...
- python3+selenium使用浏览器IE的时候,无法打开IE浏览器,老是报错: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones
python3+selenium使用浏览器IE的时候,老是报错: Unexpected error launching Internet Explorer. Protected Mode settin ...
- vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte
报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...
- 关于lr调用jar在vuser中可以运行,但是controller中却报错的问题
如题,错误如下:javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilder ...
随机推荐
- WebDev.WebServer.exe,IIS ,IIS Express
调试ASP.NET程序的服务器有三种WebDev.WebServer.exe,IIS ,IIS Express,以下是从网上整理的他们各自的优缺点,记录以备查阅 1.ASP.NET开发服务器--Cas ...
- pandas数据处理基础——基础加减乘除的运算规则
上周公司对所有员工封闭培训了一个星期,期间没收手机,基本上博客的更新都停止了,尽管培训时间不长,但还是有些收获,不仅来自于培训讲师的,更多的是发现自己与别人的不足,一个优秀的人不仅仅是自己专业那块的精 ...
- unity, Awake的调用时机
Awake是在setActive(true)时才会被调用,不过如果再setActive(false)然后重新setActive(true)的话,Awake就不会再被调用了,也就是说Awake能保证仅被 ...
- 打败 IE 的葵花宝典:CSS Bug Table
博主说:本博客文章来源包括转载,翻译,原创,且在文章内均有标明.鼓励原创,支持创作共享,请勿用于商业用途,转载请注明文章链接.本文链接:http://www.kein.pw/?p=35 原文发表于:A ...
- [svc][op]从历险压缩日志里网站pv uv统计
http://myhoop.blog.51cto.com/5556534/1367523 tomcat日志格式: http://www.cnblogs.com/anic/archive/2012/12 ...
- js获取网页宽高
<script> function getInfo() { var s = ""; s += " 网页可见区域宽:"+ document.body. ...
- linux学习笔记11---命令more
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...
- 11 jsp脚本调用java代码
大多数情况下, jsp 文档的大部分由静态文本(html)构成, 为处理该页面而创建的 servlet 只是将它们原封不动的传递给客户端, 原封不动的传送给客户端有两个小例外: 1. 如果想传送 &l ...
- Openstack(Kilo)安装系列之Keystone(四)
创建租间.用户.角色 一.To configure prerequisites 1.Configure the authentication token: export OS_TOKEN=ADMIN_ ...
- cygwin下编译zlib源代码
本文介绍在cygwin下编译zlib源代码的方法步骤,这个过程尽管简单,但还是有一些须要注意的地方. zlib源代码下载地址: http://www.zlib.net/ 下载后.解压就会生成zlib- ...