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 ...
随机推荐
- openssl C语言编码实现rsa加密
非原创, 引用自: 1 CC=gcc CPPFLAGS= -I /home/yyx//openssl-1.0.1t/include/ CFLAGS=-Wall -g LIBPATH = -L /usr ...
- Hadoop文件解压缩
Class org.apache.hadoop.io.compress .CompressionCodecFactory A factory that will find the correct co ...
- MDK5.00中*** error 65: access violation at 0xFFFFFFFC : no 'write' permission的一种解决方法
http://blog.csdn.net/coderfun/article/details/9417289 这是在调试过程中的修改方法,所以在每次运行的时候,都要设置. 先进入调试模式(crtl+F5 ...
- yum安装方式的php,切换NTS为ZTS版本
用 yum安装方式的php,切换NTS为ZTS版本(切换为线程安全版本) 最好按我这个方法安装(安装比较全一点): https://www.cnblogs.com/fps2tao/p/7699448. ...
- [MySQL] Innodb參数优化
innodb_buffer_pool_size innodb_buffer_pool_size 參数用来设置Innodb 最基本的Buffer(Innodb_Buffer_Pool)的大小,也就是缓存 ...
- Atitit. 。Jna技术与 解决 java.lang.Error: Invalid memory access
Atitit. .Jna技术与 解决 java.lang.Error: Invalid memory access 1. 原因与解决1 2. jNA (这个ms sun 的)1 3. Code1 4. ...
- Swift中UIView类方法(animateWithDuration)的使用
需求:利用Swift语言实现OC语言中UIView类方法 [UIView animateWithDuration:0.5 animations:^{ bgView.alpha= 1; }]; 在Swi ...
- 发现一个nginx LUA开发Web App的框架
nginx是个好东西, nginx的openrtsy发行版本更是个好东西. 今天又发现个好东西 :Moochine MOOCHINE - 一个简单的轻量级的web framework, 基于ngx_O ...
- sscanf及sprintf
在程序中,我们肯定会遇到许多处理字符串的操作,当然C++中的string类已经做了很好了,但是也不要忘了C中的sscanf和sprintf 这两个函数用法跟printf和scanf用法很相似,只不过数 ...
- man手册页
man手册页不同页对应的内容: 区段1:用户指令区段2:系统调用区段3:程序库调用区段4:设备区段5:文件格式区段6:游戏区段7:杂项区段8:系统指令区段9:内核内部指令区段n:Tcl或Tk指令