栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

直到几天就回来 PhantomJSDriver 发布捆绑一起 硒服务器独立-vvvjar 所以我们能够解决的方法

PhantomJSDriver()
,通过
importorg.openqa.selenium.phantomjs.PhantomJSDriver;
硒服务器独立,xyzjar

但是现在, selenium-server-standalone-vvvjar 不再捆绑 PhantomJSDriver
依赖的jar了。因此,您必须从()获取 phantomjsdriver
的版本,该版本

com.preborne:phantomjsdriver:jar:1.4.4
似乎与最新的 Selenium 版本保持最新。

下载 phantomjsdriver-1.4.4.jar 并将其添加到您的 Project中

使用以下代码块并执行

@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()
仍然可以解决
importorg.openqa.selenium.phantomjs.PhantomJSDriver;

控制台输出:

Apr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>INFO: executable: C:Utilityphantomjs-2.1.1-windowsbinphantomjs.exeApr 25, 2018 9:24:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>INFO: port: 25078Apr 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-f78193ae50b0Apr 25, 2018 9:24:20 PM org.openqa.selenium.remote.ProtocolHandshake createSessionINFO: Detected dialect: OSSGoogle[INFO  - 2018-04-25T15:54:22.023Z] ShutdownReqHand - _handle - about to shutdown


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/633104.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号