In Mac, Selenium WebDriver is launching the browser successfully but is not opening by itself - selenium

The driver path is correct and hence a new chrome browser was launched successfully and ran the actions as per the code. However, i could not see those actions, because the newly launched chrome browser is not opening by itself. So i need to click on the browser manually to see the actions going on in browser. Tried with chrome and Firefox in Mac. How will the browser opens by itself? Here is the code which i tried
package trial;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Classname
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver","/usr/local/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
}
}
Here is the console logs
Starting ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8) on port 28190
Only local connections are allowed.
May 03, 2018 11:49:00 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

Related

How to open Chrome browser console through Selenium?

I want to open chrome browser console by pressing keyboard keys Ctrl+Shift+j in selenium webdriver.
I am able to do this action using Robot class but I want this without Robot class. I have used the Actions class and Keys class using sendKeys. But I am unable to open browser console.
Is it chrome browser version issue or OS? Why the browser console is not opening using Action class and Keys class. ?
To open chrome browser console you can use the ChromeOptions class with --auto-open-devtools-for-tabs argument as follows:
Test Configuration:
Selenium: Selenium Standalone Server v3.14.0
ChromeDriver: ChromeDriver 2.46.628402
Chrome: Google Chrome 72.0.3626.96
Code Block:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class A_Chrome_Browser_Console {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("--auto-open-devtools-for-tabs");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}
Console Output:
Google
Browser Console Snapshot:
You can find a relevant python based discussion in Opening inspect (pressing F12) on Chrome via Selenium

pageLoadTimeout is not working in Selenium - Java

I am testing a website in linux host.The page i am accessing loads infinitely so I am trying to set pageLoadTimeout for selenium.
Firefox is triggered correctly but URL is not loading/navigating/added in url bar.just blank firefox window.I am not seeing any errors also.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
driver.get("http://www.example.com");
However if I remove driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS); code is working fine
Selenium version : 3.14.0;
gecko driver : 18 - linux (tested with gecko 16,17 also same issue)
browser : firefox-52
os/platform : linux
If this kind of some issue how do I make sure my driver quit itself after 5 minute.Host will support only firefox 52.
I checked this link but doesnt fix my problem.
Thanks
Jk
You can set the pageload strategy for browser which will then make the page not wait for the full page load for your other Selenium commands to be executed. Below is the sample code snippet in Java. There are three supported values:
normal
This stategy causes Selenium to wait for the full page loading (html content and subresources downloaded and parsed).
eager
This stategy causes Selenium to wait for the DOMContentLoaded event (html content downloaded and parsed only).
none
This strategy causes Selenium to return immediately after the initial page content is fully received (html content downloaded).
By default, when Selenium loads a page, it follows the normal pageLoadStrategy.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("pageLoadStrategy", "eager");
FirefoxOptions opt = new FirefoxOptions();
opt.merge(caps);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com/");
If you are interested only in the HTML of the page, better use the "eager" strategy.
You haven't mentioned the url you are trying to access but pageLoadTimeout for Selenium works as expected with With Selenium v3.14.0, GeckoDriver v0.23.0 and Firefox Quantum v62.0.3 combination. I am able to see the expected output on the console with the following example which prints TimeoutException occurred. Quiting the program whenever the pageLoadTimeout is triggered:
Code Block:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A_Firefox_Test
{
public static void main(String[] args)
{
System.setProperty("god.bless.us", "C:/Utility/BrowserDrivers/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
try {
driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl");
} catch (TimeoutException e) {
System.out.println("TimeoutException occurred. Quiting the program.");
}
driver.quit();
}
}
Console Output:
1539157195615 Marionette INFO Listening on port 1920
Oct 10, 2018 1:09:56 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Oct 10, 2018 1:10:00 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected)
TimeoutException occurred. Quiting the program.
You can find the detailed stack trace in pageLoadTimeout in Selenium not working
You can find the Pythonic approach to pageLoadTimeout in How to set the timeout of 'driver.get' for python selenium 3.8.0?

Firefox not opening the specified URL when I run my webdriver program

I am new to automation with selenium and trying to run a basic program to launch Firefox and open Google.com. But I get Firefox launched with "about:blank&utm_content=firstrun" Please help. Am on Windows 10 and Firefox version is: 48.0 (latest). I have the latest Selenium drivers and JRE versions too.
Here is my code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
}
}

Running Seleniuem web driver 2.53.0 with Firefox 47.0

I have just started running test scripts using selenium web driver. I coded the following code as a start.
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myTest {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
When I run it as Java application, It always shows the following error message.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Just the browser opens, but the facebook page doesn't get opened.
What is the solution for this?

Selenium Web Driver firefox not responding

I am using simple selenium example using Web driver classes, but the IE web driver class working fine, but the Firefox is not responding not opening browser and not throwing any error in console.
code is here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchFF {
public static void main(String args[]){
WebDriver driver=new FirefoxDriver();
System.out.println("Loading Google search page");
driver.get("http://www.google.com");
System.out.println("Google search page loaded fine");
}
}
selenium jar files added to classpath..
\selenium-java-2.13.0\selenium-2.13.0\selenium-java-2.13.0.jar
\selenium-java-client-driver-1.0.1\selenium-java-client-driver.jar
\Selenium Latest\selenium-server-standalone-2.13.0.jar
any jar is missing?
The code works for IE by setting proeprty INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS = true
Downgrade the Firefox version to 8 as Selenium 2.13.0 supports Firefox versions upto 8 only.
For reference check this log.
Instead of downgrading Firefox to 8,
You need to download the geckodriver.exe and set the System.property() by
System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
before calling WebDriver driver = new FirefoxDriver();