在高版本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的更多相关文章

  1. 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: ...

  2. Selenium click不生效 报错selenium.common.exceptions.InvalidArgumentException

    记录在使用selenium过程中踩的坑------ 在使用selenium时,用click点击网站弹出的文件上传框的"上传文件"按钮不生效,报错selenium.common.ex ...

  3. python中使用selenium调用Firefox缺少geckodriver解决方法

    from selenium import webdriver driver=webdriver.Firefox() 会报错 解决方法: 因为缺少geckodriver.exe,先到https://gi ...

  4. python+selenium遇到元素定位不到的问题,顺便记录一下自己这次的错误(报错selenium.common.exceptions.NoSuchElementException)

    今天在写selenium一个发送邮件脚本时,遇到一些没有找到页面元素的错误.经过自己反复调试,找原因百度,终于解决了.简单总结一下吧,原因有以下几点: 一:Frame控件嵌套,.Frame/Ifram ...

  5. 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 ...

  6. python无法启动火狐浏览器且报错“selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities”

    安装了python2,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'gecko ...

  7. 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 ...

  8. vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte

    报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...

  9. 关于lr调用jar在vuser中可以运行,但是controller中却报错的问题

    如题,错误如下:javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilder ...

随机推荐

  1. REP-20147 Cannot implement column link for this detail SQL query. Converting to group link.

    注:本文为原创,作为学习交流使用,转载请标明作者及出处,作者保留追究法律责任的权力. Lumen Su lzsu1989#gmail.com (#=@) www.cnblogs.com/lzsu198 ...

  2. Handler源代码解析-有关Handler那些事

    Handler被成为异步处理大师.相信大家都会用,面试中也常常会问到Handler的底层原理.今天就来看一看Handler的机制. Android的消息处理有四个核心类:Handler.Looper. ...

  3. stl之hash_multiset

    hash_multiset的元素不会被自己主动排序

  4. unity, access standard shared emission by script

    unity 5.1.1f1 personal 用下面方法在脚本中设置standard shader的emssion: gameObject.GetComponent<MeshRenderer&g ...

  5. Mongodb更新数组$sort操作符

    db.students.update( { _id: 1 }, { $push: { quizzes: { $each: [ { id: 3, score: 8 }, { id: 4, score:  ...

  6. SecureCRT终端上使用spark-shell时按退格键无反应的解决方法

    问题:用SecureCRT远程连接至Spark集群,启动spark-shell却发现输错命令后却无法用退格键删除. 解决方法: 第一步: 在SecureCRT的菜单栏选择“OPtions(选项)”按钮 ...

  7. atitit.软件设计模式大的总结attialx总结

    atitit.软件设计模式大的总结attialx总结 1. 设计模式的历史3 2. 设计模式的数量(253个)3 3. 设计模式的结构4 3.1. 应用场景and条件Context4 3.2. Pro ...

  8. redis命令_INCR

    INCR key 将 key 中储存的数字值增一. 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作. 如果值包含错误的类型,或字符串类型的值不能表示为数字,那 ...

  9. PHP7:10件事情你需要知道的

    你是一个Web开发人员或网站所有者?做你的网站上的PHP-enabledCMS如WordPress,Drupal的是,Joomla或Magento的运行?然后,我对你的好消息:新的PHP 7的功能完整 ...

  10. poj 1636 Prison rearrangement

    Prison rearrangement   Time Limit: 3000MS   Memory Limit: 10000K Total Submissions: 2158   Accepted: ...