samedi 18 juin 2016

PhantomJS WebDriver headless: ".click" Method has no effect

I hope somebody can help me with my phantomJS problem. I'm running version 1.9.8 on unix 64bit as a node that registers to a selenium hub running on jenkins. If I navigate to a HTML page with a link (which has no ID or name, which is why I'm addressing it via xpath - Unfortunately I cannot change the html code as it is external input), I'm trying to click it to navigate to the upcoming page. Using Firefox Driver this worked without any problems, and if I start a local selenium server (windows, phantomJS v. 1.9.8), it works aswell.

My code:

System.out.println("current url before click: " + getDriver().getCurrentUrl());
getDriver().findElement(By.xpath("//a")).click();
System.out.println("current url after click: " + getDriver().getCurrentUrl());

Output on local selenium (windows):

current url before click: https://initialpage.html
current url after click: https://www.my-link.com

Output on remote selenium grid (unix):

current url before click: https://initialpage.html
current url after click: https://initialpage.html

There is no error or similar, it just seems like the driver does stay on the old page. I already tried different phantomjs.cli.args while instantiating the WebDriver, adding several thread.sleep()'s and replacing click() by

getDriver().navigate().to(getDriver().findElement(By.xpath("//a")).getAttribute("href")); 

but the output stays the same.

Just in case it matters, here is how I instantiate the webdriver:

 driver = new RemoteWebDriver(new URL("http://servername:4444/wd/hub"), DesiredCapabilities.phantomjs());

I appreciate any help, thanks for the effort guys! If there are any questions left, feel free to ask! Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire