Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've got a Selenium project + Java + Maven that runs normally on Chrome driver. However, I've been trying to make it work with PhantomJS, but I've encountered a problem. The same code that works on Chrome driver doesn't work on PhantomJS. I've debugged a lot and realized that the problem is that the page source that gets loaded is different with PhantomJS. The IDs that I try to locate are not present.

When using System.out.println(driver.getPageSource());, the output for: Chrome driver: length: 19,233 PhantomJS driver: length: 14,965

I've tried to set size as someone suggested in another post (driver.manage().window().setSize(new Dimension(2000, 1500));), but that doesn't help either.

I've tried waiting longer for the page to load, didn't help.

I've also checked the link in driver.get() and it's a full URL with http:// at the beginning.

As we're going to need all the tests to run both on Chrome and on PhantomJS, I'd rather if we didn't need to check the PageSource everytime we write a test and look for something that's present on both.

I'd appreciate any help. :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
168 views
Welcome To Ask or Share your Answers For Others

1 Answer

PhantomJs is having bug these days because of poorly maintenance of it.

You can use chromedriver itself for headless jobs.

You just need to pass one option in chromedriver as below:-

    chromeOptions.addArguments("--headless");

Full code will appear like this :-

System.setProperty("webdriver.chrome.driver","D:\Workspace\JmeterWebdriverProject\src\lib\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.co.in/");

Hope it will help you :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...