i extract some data from webpage,i have use phantomjs but it shows phantomjs console++ error . so please tell me another way to minimize the browser
You can't minimize phantomjs, since it is a headless browser. You can use https://github.com/MachinePublishers/jBrowserDriver jbrowser driver instead of phantomjs.
Related
I'm trying to load a website with Chrome browser in headless mode using Selenium web driver. I face an issue with some specific websites. The page is loading, in the first 2-3 seconds it shows a page with "please enable javascript..." and after 3 seconds, page source goes blank.
I'm using Selenium and especially Chrome for long time and I am familiar with the platform. For the purpose of this case, I'm using Chrome Version 73.0.3683.86 , ChromeDriver 2.46.628411 (which is compatible according to Which ChromeDriver version is compatible with which Chrome Browser version?) on a Mac OS. selenium java version is latest - 3.141.59
I suspect that headless Chrome cannot handle specific content-type such as "svg" and any other GUI related HTTP response.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://identity.tescobank.com/login");
Thread.sleep(3000);
System.out.println(driver.getPageSource());
driver.quit();
Expected result is to have the page source same as it is showing in non-headless mode.
Headless Chrome should be able to handle everything the normal Chrome can do:
It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.
(see https://developers.google.com/web/updates/2017/04/headless-chrome)
Since only the login page of a bank causes you trouble, my guess is that the security of the page detects an anomaly and decides not to serve you.
One way they can do that is by looking at the User Agent string which contains HeadlessChrome.
That said, unless you're writing integration tests for the bank, your behavior is at least suspicious. If you have a valid and legal concern, clear it with the bank first. They might take actions against you, otherwise. Blocking your IP address (which could affect many people) or asking the police to have a word with you.
I was facing similar issue in my script, after login. Somehow refreshing the page resolved the issue.
driver.navigate().refresh();
I'm planning to use Selenium Chrome Driver for my project which will be used to do web scraping to multiple public websites (something like kayak or skyscanner). So there will be a REST GET endpoint where my backend would launch headless Chrome to scrape multiple websites, and eventually return a manipulated JSON.
I want to know how scalable is Chrome Driver as it sounds like a headless Chrome instance needs to be launched whenever a request comes in.
Updated: Question using Google Chrome Headless
Please find the pros and cons of phantom js which I noticed during implementation .Hope this helps.
Cons:
1)It will fail to recognize the browser elements like id,xpath,csselector
when compared to chrome driver.
2)If you have login mechanism ,redirects won't work as you expect when compared to chrome driver.
3)You need to manually implement the custom logic for screen shots for the test failures if you need it.
4)If you want to switch between multiple drivers like chrome,html etc then it is very difficult
Pros:
1)Test case execution is faster when compared to chrome driver
2)No browser is required it will run without GUI.
3)No much configurations are needed when compared to chromedriver.
You can go with html driver also which is quite faster then phantom but even it has its own limitations that you need take care of before implementation.
I am not sure that you really need to use PhantomJS.
Chrome implemented "headless" mode couple of months ago.
"Headless Chrome" does the same job that PhantomJS, and does it better.
I heard that PhantomJS authors even said that they will not support it anymore.
You can enable headless mode in Selenide with just on line:
Configuration.headless = true;
Did you think about headless chrome?
Headless Chrome
We have a terminal application which serves webcontent via iFrames to our clients.
For some reason, it has been decided that we want to automate the test for this server side. I need to visit a page, fill out a form, and submit it - without actually rendering it in a GUI, I believe a headless selenium driver can do this - but I am new to selenium, does anyone have an example of how to do this in java with selenium?
You can use PhantomJS. Here you can find a working example.
At the moment, I use Firefox as browser for my Java Application with Selenium. But Firefox is slow.
Is it possible to use Yandex as browser? Didn't find anything in Google. Does Selenium supports Yandex? For Chrome I need the .exe for using Chrome as browser. Is this possible with Yandex?
From what I recall, there is no WebDriver for the Yandex ("Яндекс") browser. In other words, there is no way to automate this browser through selenium.
Also, there are some performance tips and further links here:
Selenium WebDriver works but SLOW (Java)
Yandex browser can work with Selenium WebDriver using Operadriver.
System.setProperty("webdriver.opera.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\operadriver.exe");
OperaOptions options = new OperaOptions();
options.setBinary("C:\\Users\\User\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe");
WebDriver driver = new OperaDriver(options);
driver.get("https://docs.seleniumhq.org");
This might be what you are looking for ( 4 years later :) ):
https://github.com/yandex/YandexDriver
I am running test in java selenium test using firefox/chrome driver
I want to run the test in background.
In ruby, i use this gem
https://rubygems.org/gems/headless
How to do in java?
There is a new Firefox headless mode https://developer.mozilla.org/en-US/Firefox/Headless_mode
There is an example of how to use it in Node.js
One would think that would translate over to Java quite well. I'm going to give it a shot.
Other option is using the HtmlUnitDriver which based on HtmlUnit project which "GUI less browser".
//create webdriver
WebDriver driver = new HtmlUnitDriver();