相关参考博客
【Selenium】Raspbian+Selenium+Firefox
firefox、geckodriver.exe、selenium-server-standlone版本对应及下载地址
树莓派如何安装火狐浏览器和geckodriver
geckodriver下载


前提:
最近需要在树莓派通过Java调用driver然后打开浏览器展示某些测试页面。
一开始通过Chromedriver结合Selenium调用Chrome,本地windows测试一切正常,部署至树莓派就会出现各种各样的问题,主要是driver与chrome和Selenium版本兼容问题导致不成功。
后来转向通过Selenium调用geckodriver控制firefox,成功展示相关页面。

1.首先树莓派安装Firefox

  1. sudo apt-get install firefox-esr -y

  通过以上命令进行firefox安装,安装成功后,可通过 whereis firefox 查看火狐浏览器安装路径.通常情况下在 /usr/bin/firefox 目录下。

  查看火狐浏览器版本:

  firefox -version

  我的树莓派安装的版本为52,例如: Mozilla Firefox .*.*

  另:也可通过ftp mozilla下载对应版本进行安装。

2.选择合适的geckodriver

  可通过mozilla/geckodriver下载相关版本的 geckodriver 。

  本地树莓派火狐浏览器版本为52,所以 geckodriver下载 v0.15.0 版本即可geckodriver-v0.15.0-arm7hf.tar.gz

  将下载后的包通过解压缩命令解压:

  tar -zxvf geckodriver-v0.15.0-arm7hf.tar.gz

  将解压后的文件 geckodriver 复制至 /usr/bin/ 目录下,并添加执行权限(+x)。

3.选择相应版本的Selenium

  选择3.3.1版本的Selenium: selenium-server-standlone-3.3..jar .下载地址:http://selenium-release.storage.googleapis.com/index.html

  一开始选择的是 selenium-java-3.3..jar ,调用过程异常,发现依赖进来的相关包的版本却是3.14.版本的,例如:selenium-firefox-3.14..jar ,修改为 selenium-server-standlone-3.3..jar 后正常。

4.测试

  1. System.setProperty("webdriver.gecko.driver","/usr/bin/geckodriver");
  2. FirefoxOptions firefoxOptions = new FirefoxOptions();
  3. List<String> firefoxOp = new ArrayList<String>(10);
  4. .....
  5. firefoxOptions.addArguments(firefoxOp);
  6. WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);
  7. firefoxDriver.manage().window().maximize();
  8. firefoxDriver.get("https://www.baidu.com");

  运行代码,树莓派上能够正常打开火狐浏览器并转向相关测试页。

5.总结

  • Firefox、selenium、geckodriver最难的是版本兼容,否则各种问题。
  • Firefox、geckodriver、selenium-server-standlone版本对应如下:
  1. selenium-server-standlone-3.3.1.jar http://selenium-release.storage.googleapis.com/index.html
  2. geckodriver V.15.0 https://github.com/mozilla/geckodriver/releases
  3. firefox 52.*.* http://ftp.mozilla.org/pub/firefox/releases/

6.注

  在使用如下代码全屏浏览器时,会提示异常:firefoxDriver.manage().window().fullscreen();

  在 geckodriver 是 0.15.0 版本会报错,提示: org.openqa.selenium.UnsupportedCommandException: unknown command: session/b368564bbe1863857d7ce10cc5f38e38/window/fullscreen.

  此处是一个issue,该命令需要 0.17 版本以上,见原文Selenium 3 : Virtual - driver.manage().window().fullscreen() throwing org.openqa.selenium.UnsupportedCommandException.

 This command is only supported in GeckoDriver since 0.17. Please try with latest GeckoDriver and, if it still doesn't work, provide a concise reproducible test case so that we could act on this issue.

树莓派安装Firefox+Selenium+geckodriver的更多相关文章

  1. 树莓派.安装Firefox浏览器

    sudo apt-get install firefox-esr 要做全屏效果的话, 可以加装插件FF Fullscreen 插件地址: https://addons.mozilla.org/en-U ...

  2. 在Centos7上安装Python+Selenium+Firefox+Geckodriver

    1.事先准备好Centos7的系统 Centos系统是CentOS Linux release 7.4.1708 (Core) 查看Centos内核版本命令cat /etc/centos-releas ...

  3. 在Centos7下安装Python+Selenium+Firefox学习环境

    Selenium 一自动化测试工具.它支持 Chrome,Safari,Firefox 等主流界面式浏览器,如果你在这些浏览器里面安装一个 Selenium 的插件,那么便可以方便地实现Web界面的测 ...

  4. 在Centos7下docker配置自动化环境镜像(python3.7+selenium 3.11+firefox 62+geckodriver 0.21)

    最近在学习Docker,准备做自动化测试代码集成的功能.如下文章的前提是已经安装好linux系统,且成功安装好Docker. 接下来我会按步骤一步一步的对自动化需要的一些环境进行安装,如果没有特别说明 ...

  5. 5--Selenium环境准备--firefox与geckodriver

    selenium2时打开firefox浏览器是不需要安装firefoxdriver的,但是selenium3不支持向前支持火狐浏览器了,40以后版本的火狐,运行会出现问题. 1.下载geckodriv ...

  6. 自动化测试_Mac安装python+selenium

    1.下载安装(参照下文) https://blog.csdn.net/kacylining/article/details/60587484 https://www.zhihu.com/questio ...

  7. chromedriver与chrome版本对应表,firefox、geckodriver

     一. chromedriver与chrome对应表(记得就会更新): chromedriver版本 支持的Chrome版本 v2.36 v64-66 v2.35 v62-64 v2.34 v61-6 ...

  8. Firefox 与 geckodriver 版本兼容问题

    打开 python shell,执行以下脚本: from selenium import webdriverdriver = webdriver.Firefox()driver.maximize_wi ...

  9. Ubuntu全新安装firefox最新版本

    Ubuntu默认安装firefox,但是自带的软件仓库是不会随firefox更新的,我在使用中老是提示flash插件需要激活,提示中可选的解决方式有三种 1.更新flash插件,但是跳转到adobe的 ...

随机推荐

  1. DS-博客作业07

    1.本周学习总结(0--2分) 1.1思维导图 1.2 谈谈你对查找运算的认识及学习体会. 在查找这一章,我学习的比较认真,但是还是有部分没太清楚.这章没有前一章树那么多的代码要记,但是还是要用心. ...

  2. python编码,三个编码实例

    1.字符串编码设置 data = u'你好' utf8 = data.encode('utf-8') 2.管道编码设置 import locale import sys ###设置输出管道编码### ...

  3. POJ 2488 -- A Knight's Journey(骑士游历)

    POJ 2488 -- A Knight's Journey(骑士游历) 题意: 给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. 经典的“骑士游历”问题 ...

  4. 指定pip清华源

    临时指定: pip install cefpython3 -i https://pypi.tuna.tsinghua.edu.cn/simple 一直使用:pip的配置文件为%HOME%/pip/pi ...

  5. iommu是干什么的呢?

    答: 如普通的mmu,将虚拟内存地址转换为物理地址,不同的是,iommu是将设备访问的虚拟地址转换为物理地址

  6. LC 722. Remove Comments

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the  ...

  7. hibernate关联映射之多对多

    package loaderman.c_many2many; import java.util.HashSet; import java.util.Set; /** * 开发人员 * * */ pub ...

  8. iOS 隐藏导航栏后,UITableView向下偏移状态栏高度

    if (@available(iOS 11.0, *)) { self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewConte ...

  9. Linux系统调优相关工具

    一.系统调优概述 系统的运行状况: CPU -> MEM -> DISK*-> NETWORK -> 应用程序调优 分析是否有瓶颈(依据当前应用需求) 调优(把错误的调正确) ...

  10. Delphi 10.2.3 精简版自动激活Embarcadero Delphi 10.2.3 v25.0.29899.2631 Lite v14.4

    下载:https://maxwoods.ctfile.com/u/758954/28516301 Embarcadero.Delphi.10.2.RTM.v25.0.26309.314.Lite.v1 ...