<legend id='Y7N0s'><style id='Y7N0s'><dir id='Y7N0s'><q id='Y7N0s'></q></dir></style></legend>
      <bdo id='Y7N0s'></bdo><ul id='Y7N0s'></ul>
    1. <small id='Y7N0s'></small><noframes id='Y7N0s'>

      <i id='Y7N0s'><tr id='Y7N0s'><dt id='Y7N0s'><q id='Y7N0s'><span id='Y7N0s'><b id='Y7N0s'><form id='Y7N0s'><ins id='Y7N0s'></ins><ul id='Y7N0s'></ul><sub id='Y7N0s'></sub></form><legend id='Y7N0s'></legend><bdo id='Y7N0s'><pre id='Y7N0s'><center id='Y7N0s'></center></pre></bdo></b><th id='Y7N0s'></th></span></q></dt></tr></i><div id='Y7N0s'><tfoot id='Y7N0s'></tfoot><dl id='Y7N0s'><fieldset id='Y7N0s'></fieldset></dl></div>

        <tfoot id='Y7N0s'></tfoot>

        如何通过 Selenium Java 初始化 PhantomJS 浏览器

        时间:2023-07-13

          • <legend id='lgsEt'><style id='lgsEt'><dir id='lgsEt'><q id='lgsEt'></q></dir></style></legend>
              • <bdo id='lgsEt'></bdo><ul id='lgsEt'></ul>

              • <small id='lgsEt'></small><noframes id='lgsEt'>

                  <tbody id='lgsEt'></tbody>
              • <i id='lgsEt'><tr id='lgsEt'><dt id='lgsEt'><q id='lgsEt'><span id='lgsEt'><b id='lgsEt'><form id='lgsEt'><ins id='lgsEt'></ins><ul id='lgsEt'></ul><sub id='lgsEt'></sub></form><legend id='lgsEt'></legend><bdo id='lgsEt'><pre id='lgsEt'><center id='lgsEt'></center></pre></bdo></b><th id='lgsEt'></th></span></q></dt></tr></i><div id='lgsEt'><tfoot id='lgsEt'></tfoot><dl id='lgsEt'><fieldset id='lgsEt'></fieldset></dl></div>
                  <tfoot id='lgsEt'></tfoot>

                1. 本文介绍了如何通过 Selenium Java 初始化 PhantomJS 浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Java 中的 phantomjsdriver 来构建 Webspider.我正在使用 Selenium 版本 3.11.0、PhantomJS 2.1.1 和 phantomjsdriver 版本 1.2.1.当我执行我的代码时,我收到以下错误消息.

                  I am trying to use the phantomjsdriver in Java to build a Webspider. I am using Selenium Version 3.11.0, PhantomJS 2.1.1 and the phantomjsdriver Version 1.2.1. When i am executing my code I get the following error Message.

                  线程main"中的异常 java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;

                  Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;

                  package Masterarbeit.Crawler;
                  import java.io.File;
                  import org.openqa.selenium.WebDriver;
                  import org.openqa.selenium.phantomjs.PhantomJSDriver;
                  
                  public class Test {
                  
                      public String Test(){
                          File path=new File("/usr/local/bin/phantomjs");
                          System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
                          WebDriver driver = new PhantomJSDriver(); 
                          return "successful";
                  
                      }
                  }
                  

                  我的操作系统是 Linux Mint 18 Sarah,有人知道原因吗?

                  My OS is Linux Mint 18 Sarah, does anybody know a reason for this?

                  推荐答案

                  几天前 PhantomJSDriverselenium-server-standalone-vvvjar 一起发布所以我们能够通过 selenium 中的 import org.openqa.selenium.phantomjs.PhantomJSDriver; 解决方法 PhantomJSDriver()-server-standalone-xyzjar

                  Till a few days back PhantomJSDriver was released bundled along with selenium-server-standalone-v.v.v.jar so we were able to resolve the method PhantomJSDriver() through import org.openqa.selenium.phantomjs.PhantomJSDriver; from the selenium-server-standalone-x.y.z.jar

                  但现在,selenium-server-standalone-v.v.v.jar 不会为 PhantomJSDriver 依赖项捆绑 jar.因此,您必须从 (com.codeborne:phantomjsdriver:jar:1.4.4) 获取似乎与最新的 selenium 版本保持同步的 phantomjsdriver 版本.

                  But now, selenium-server-standalone-v.v.v.jar doesn't bundles the jar for PhantomJSDriver dependency. So you have to obtain a version of phantomjsdriver from (com.codeborne:phantomjsdriver:jar:1.4.4) that appears to be kept up to date with latest selenium releases.

                  下载 phantomjsdriver-1.4.4.jar 并将其添加到您的项目.

                  Download and add the phantomjsdriver-1.4.4.jar to your Project.

                  使用以下代码块并执行您的 @Test :

                  Use the following code block and execute your @Test :

                  import java.io.File;
                  
                  import org.openqa.selenium.WebDriver;
                  import org.openqa.selenium.phantomjs.PhantomJSDriver;
                  
                  public class phantomJS_launch {
                  
                      public static void main(String[] args) {
                  
                  
                            File path=new File("C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe");
                            System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
                            WebDriver driver= new PhantomJSDriver();
                            driver.get("https://www.google.co.in");
                            System.out.println(driver.getTitle());
                            driver.quit();
                  
                      }
                  
                  }
                  

                  重要:PhantomJSDriver()仍然通过import org.openqa.selenium.phantomjs.PhantomJSDriver解析;

                  控制台输出:

                  Apr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
                  INFO: executable: C:Utilityphantomjs-2.1.1-windowsinphantomjs.exe
                  Apr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
                  INFO: port: 25078
                  Apr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
                  INFO: arguments: [--webdriver=25078, --webdriver-logfile=C:UsersAtechM_03LearnAutmationJava_PhantomJSphantomjsdriver.log]
                  Apr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
                  INFO: environment: {}
                  [INFO  - 2018-04-25T15:54:19.809Z] GhostDriver - Main - running on port 25078
                  [INFO  - 2018-04-25T15:54:20.263Z] Session [ea9746f0-48a0-11e8-8b6b-f78193ae50b0] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
                  [INFO  - 2018-04-25T15:54:20.263Z] Session [ea9746f0-48a0-11e8-8b6b-f78193ae50b0] - page.customHeaders:  - {}
                  [INFO  - 2018-04-25T15:54:20.263Z] Session [ea9746f0-48a0-11e8-8b6b-f78193ae50b0] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
                  [INFO  - 2018-04-25T15:54:20.264Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: ea9746f0-48a0-11e8-8b6b-f78193ae50b0
                  Apr 25, 2018 9:24:20 PM org.openqa.selenium.remote.ProtocolHandshake createSession
                  INFO: Detected dialect: OSS
                  Google
                  [INFO  - 2018-04-25T15:54:22.023Z] ShutdownReqHand - _handle - About to shutdown
                  

                  在这里您可以找到关于 如何从另一个 jar 中解析我的类,该 jar 具有与另一个相同的结构

                  Here you can find a detailed discussion on How can I resolve my class from a different jar with same structure like another

                  这篇关于如何通过 Selenium Java 初始化 PhantomJS 浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <legend id='ozy92'><style id='ozy92'><dir id='ozy92'><q id='ozy92'></q></dir></style></legend>

                  <i id='ozy92'><tr id='ozy92'><dt id='ozy92'><q id='ozy92'><span id='ozy92'><b id='ozy92'><form id='ozy92'><ins id='ozy92'></ins><ul id='ozy92'></ul><sub id='ozy92'></sub></form><legend id='ozy92'></legend><bdo id='ozy92'><pre id='ozy92'><center id='ozy92'></center></pre></bdo></b><th id='ozy92'></th></span></q></dt></tr></i><div id='ozy92'><tfoot id='ozy92'></tfoot><dl id='ozy92'><fieldset id='ozy92'></fieldset></dl></div>

                  1. <tfoot id='ozy92'></tfoot>
                      • <bdo id='ozy92'></bdo><ul id='ozy92'></ul>
                          <tbody id='ozy92'></tbody>

                          <small id='ozy92'></small><noframes id='ozy92'>