在高版本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. jmeter ---集合点使用方法:Synchronizing Timer

    LR中集合点可以设置多个虚拟用户等待到一个点,同时触发一个事务,以达到模拟真实环境下多个用户同时操作,实现性能测试的最终目的. jmeter中使用Synchronizing Timer实现Lr中集合点 ...

  2. Spring Boot(三):logback打印日志

    springboot对logback的支持是非常好的,不需要任何配置,只需要在resource下加logback.xml就可以实现功能直接贴代码: <?xml version="1.0 ...

  3. Atitit 《摩奴法典》overivew 读后感 不是由国王 颁布的,而是 僧侣编制

    Atitit <摩奴法典>overivew 读后感 不是由国王 颁布的,而是 僧侣编制 1. <摩奴法典>是印度最古老的一部法律文献.该法典不是由国王或立法机关制定颁布的,而是 ...

  4. python学习之with...as语句

    python中的with...as...语句类似于try...finally...语句: # -*- coding: utf-8 -*- # """ with...as. ...

  5. [转]c++ 为什么要将基类的析构函数声明为Virtual?

    http://www.cnblogs.com/alephsoul-alephsoul/archive/2012/10/12/2721410.html

  6. jsp tld 的tag 自定义标签扩展

    引入方式 <%@ taglib prefix="bgt" uri="/WEB-INF/tlds/bgt.tld" %> 写法示例如下: <?x ...

  7. python练习题3--for

    题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 程序分析: 假设该数为 x. 1.则:x + 100 = n2, x + 100 + 168 = m2 ...

  8. linux学习笔记22---命令diff和diff3

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...

  9. 1.1 Application Fundamentals - 应用原理

    Android应用是使用Java编程语言编写的.Android SDK工具把代码.资源和数据文件编译为一个Android包,这是一个有.apk后缀的压缩文件.一个单独的.apk文件里包含所有的代码,这 ...

  10. jQuery 时间戳转化成时间

    //时间转换  function   formatDate(now)   { var   now= new Date(now);      var   year=now.getFullYear();  ...