selenium+firefox(geckodriver marionetteProtocol)

selenium+firefox(geckodriver marionetteProtocol)



环境:
CentOS7
python-3.5.2
selenium-3.0.1
firefox-38.3.0-2.el7.centos.x86_64

报错1 'geckodriver':
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH

原因:
selenium 3.x开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而2.x是executable_path="wires"
firefox 47以上版本,需要下载第三方driver,即geckodriver

解决:
到geckodriver官网找到对应运行平台的驱动,解压至PATH路径即可
https://github.com/mozilla/geckodriver/releases

curl -sSL https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz|tar -xvf - -C /usr/local/bin --gzip



报错2 'marionetteProtocol' :
selenium.common.exceptions.WebDriverException: Message: Missing 'marionetteProtocol' field in handshake

解决:
升级到firefox-45.5 LTS后正常
firefox升级略




环境:
win8.1
python-2.7.12
selenium-3.0.1
firefox-49.0.2
报错3 no 'moz:firefoxOptions.binary' :
selenium+firefox(geckodriver <wbr>marionetteProtocol)

原因:
在PATH路径中没找到firefox的二进制文件

解决:
添加firefox到PATH路径
selenium+firefox(geckodriver <wbr>marionetteProtocol)



环境:
macOS 10.12.1
python-2.7.12
selenium-3.0.1
firefox-47.0.1

读取指定profile:
当测试需要用到插件或者已经导入的证书(比如银行金融和安全加密行业)时,需要事先安装好相应的加密插件。
而selenium启动firefox时会打开一个全新的实例,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的那个firefox),这种情况下就要用firefoxprofile了。

先新建一个profile或者直接使用默认,最快捷的方法就是把默认的profile拷贝一份出来。
关于firefox的profile  管理用户配置文件 。
selenium+firefox(geckodriver <wbr>marionetteProtocol)

selenium+firefox(geckodriver <wbr>marionetteProtocol)

/Users/jlive/Library/Application Support/Firefox/Profiles/683p874u.default
python版selenium只需修改如下两行
profile = webdriver.FirefoxProfile(’/Users/jlive/Library/Application Support/Firefox/Profiles/683p874u.default’)  # 指定profile
driver = webdriver.Firefox(profile)  # 打开浏览器


转载于:https://www.cnblogs.com/lixuebin/p/10814000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用SeleniumFirefox进行带用户名密码认证的HTTP代理操作可以按照以下步骤进行: 1. 安装Firefox浏览器,并安装FoxyProxy Standard插件。 2. 配置FoxyProxy,添加代理服务器地址和端口号,并选择“HTTP代理”类型。 3. 在FoxyProxy的“身份验证”选项卡中,填写代理服务器的用户名和密码,保存设置。 4. 在Python中使用Selenium启动Firefox浏览器,并使用FirefoxProfile设置代理服务器。 5. 在Firefox浏览器中访问需要使用代理服务器的网站,即可自动使用设置好的代理服务器进行访问。 下面是一个示例代码: ``` from selenium import webdriver from selenium.webdriver.common.proxy import Proxy, ProxyType # 创建FirefoxProfile对象 firefox_profile = webdriver.FirefoxProfile() # 设置代理服务器地址和端口号 proxy_url = "http://proxy.server.com:port" firefox_profile.set_preference("network.proxy.type", 1) firefox_profile.set_preference("network.proxy.http", proxy_url) firefox_profile.set_preference("network.proxy.http_port", 80) # 设置代理服务器的用户名和密码 proxy_username = "username" proxy_password = "password" firefox_profile.set_preference("extensions.foxyproxy.proxyPassword", proxy_password) firefox_profile.set_preference("extensions.foxyproxy.proxyUsername", proxy_username) # 启动Firefox浏览器 driver = webdriver.Firefox(firefox_profile=firefox_profile) # 访问需要使用代理服务器的网站 driver.get("https://www.example.com") ``` 这样,就可以使用带用户名密码认证的HTTP代理了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值