【问题标题】:PhantomJS: How To Handle redirected URls like https?PhantomJS:如何处理重定向的 URL,如 https?
【发布时间】:2014-02-04 10:50:56
【问题描述】:

我正在尝试使用 PhantomJS 驱动程序进行 Headless 测试。问题是:无法处理重定向的 URL 前 URL:https://gmail.com

环境:phantomjs-1.9.7-windowsphantomjsdriver: 1.0.4 ; junit :4.8.1 ; 硒服务器:2.39.0

控制台:

Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Users\xprk067\softwares\phantomjs-1.9.7-windows\phantomjs.exe
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 7070
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=7070]
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
PhantomJS is launching GhostDriver...
[ERROR - 2014-02-04T10:42:34.998Z] GhostDriver - main.fail - {"message":"Could not start Ghost Driver","line":82,"sourceId":79376088,"sourceURL":":/ghostdriver/main.js","stack":"Error: Could not start Ghost Driver\n    at :/ghostdriver/main.js:82","stackArray":[{"sourceURL":":/ghostdriver/main.js","line":82}]}
OUTPUT:blank

这是我用过的代码

public class PhantamJS{

    private WebDriver driver;
    private WebDriver driver2;

    @Test
    public void  test(){                        

        **PhantomJSDriver to get the current URL  : Not Working**       
        Proxy proxy = new Proxy();
        PhantomJSDriverService driverService = new PhantomJSDriverService.Builder()
        .usingPhantomJSExecutable(new File("C:\\Users\\amar\\softwares\\phantomjs-1.9.7-windows\\phantomjs.exe"))
        .usingPort(7070)
        .build();
        final DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, proxy);
        driver2 = new PhantomJSDriver(driverService, capabilities);
        driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver2.get("https://gmail.com");           
        String currentURL2 = driver2.getCurrentUrl();             
System.out.println("OUTPUT" + currentURL2 );
    }
}

【问题讨论】:

  • 正如您在日志中看到的,问题不在于 https,而在于 ghostdriver。它根本没有启动:“无法启动 Ghost 驱动程序”。这就是为什么你可以浏览gmail.com

标签: javascript phantomjs ghostdriver


【解决方案1】:

您需要解决 window.setTimeout 并在 url 请求时增加参数。

此线程将帮助您: https://github.com/ariya/phantomjs/issues/10389

【讨论】:

  • 嗨 Yogesh,你知道如何通过 GhostDirver 设置这个参数吗?
  • 不知道如何在 GhostDriver 中做,这个 JS 中的例子可以帮助你,检查 window.setTimeout 是如何设置的:github.com/ariya/phantomjs/blob/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
  • 1970-01-01
  • 2020-08-07
  • 2014-09-03
  • 1970-01-01
  • 2016-04-11
相关资源
最近更新 更多