user3270404
user3270404

Reputation: 21

PhantomJS: How To Handle redirected URls like https?

I am trying do Head less Testing with PhantomJS Driver. Problem is : Unable to work on redirected URLS ex URL : https://gmail.com

Environment : phantomjs-1.9.7-windows ; phantomjsdriver: 1.0.4 ; junit :4.8.1 ; selenium-server : 2.39.0

Console:

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

here is the code which i have used

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 );
    }
}

Upvotes: 1

Views: 10460

Answers (1)

Yogesh Unavane
Yogesh Unavane

Reputation: 265

You need to workaround with window.setTimeout and increase the parameter while url requesting.

This thread will help you in this : https://github.com/ariya/phantomjs/issues/10389

Upvotes: 1

Related Questions