相关参考博客
【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

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

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

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

5.总结

  • Firefox、selenium、geckodriver最难的是版本兼容,否则各种问题。
  • Firefox、geckodriver、selenium-server-standlone版本对应如下:
selenium-server-standlone-3.3.1.jar      http://selenium-release.storage.googleapis.com/index.html
geckodriver V.15.0 https://github.com/mozilla/geckodriver/releases
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. Android网络编程之——文件断点下载

    一:关于断点下载所涉及到的知识点 1.对SQLite的增删改查(主要用来保存当前任务的一些信息) 2.HttpURLConnection的请求配置 HttpURLConnection connecti ...

  2. Permission权限大全

    访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...

  3. 怎么去检测浏览器支不支持html5和css3?

    HTML5, CSS3 以及其他相关技术例如 Canvas.WebSocket 等等将 Web 应用开发带到了一个新的高度. 该技术通过组合 HTML.CSS 和 JavaScript 可以开发出桌面 ...

  4. Selenium 2自动化测试实战41(多线程技术)

    多线程技术 python通过两个标准库thread和threading提供对线程的支持.thread提供了低级别的,原始的线程以及一个简单的锁.threading基于Java的线程模型设计. 1.th ...

  5. dede不同栏目调用不同banner图的方法

    用顶级栏目ID 方法: <img src="{dede:global.cfg_templets_skin/}/images/{dede:field.typeid function=&q ...

  6. 从Myeclipse到IntelliJ IDEA-——让你摆脱鼠标,全键盘操作

    注:本文是对原文章(https://blog.csdn.net/luoweifu/article/details/13985835)做的补充 快捷键对比 Myeclipse IDEA 说明 Ctrl+ ...

  7. sql server 备份语句

    1.BACKUP DATABASE your_database TO DISK = 'diff.bak'with DIFFERENTIAL #差异备份,仅备份数据2.BACKUP DATABASE y ...

  8. Tensorflow 保存模型 & 在java中调用

    本节涉及: 保存TensorFlow 的模型供其他语言使用 java中调用模型并进行预测计算 一.保存TensorFlow 的模型供其他语言使用 如果用户选择“y” ,则执行下面的步骤: 判断程序执行 ...

  9. HADOOP依赖

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  10. 鸟哥私房菜基础篇:磁碟配额(Quota)与进阶文件系统管理习题

    猫宁!!! 参考:http://cn.linux.vbird.org/linux_basic/0420quota.php 1-在前一章的第一个大量新增帐号范例中, 如果我想要让每个用户均具有 soft ...