zoukankan      html  css  js  c++  java
  • 树莓派安装Firefox+Selenium+geckodriver

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

      另:也可通过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.1.jar .下载地址:http://selenium-release.storage.googleapis.com/index.html

      一开始选择的是 selenium-java-3.3.1.jar ,调用过程异常,发现依赖进来的相关包的版本却是3.14.1版本的,例如:selenium-firefox-3.14.1.jar ,修改为 selenium-server-standlone-3.3.1.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. 

  • 相关阅读:
    CF140CNew Year Snowmen
    ZR10.1青岛集训三地联考
    CF1228——记一次和紫名失之交臂的CF
    CF1220
    codeforce 382 div2 E —— 树状dp
    codeforce 381 div2
    codeforce 380(div.2)
    Bishops Alliance—— 最大上升子序列
    codeforce 379(div.2)
    模板——BigInteger
  • 原文地址:https://www.cnblogs.com/Java-Script/p/11095930.html
Copyright © 2011-2022 走看看