0
votes

I am trying to launch the selenium web browser I am able to open the Firefox browser but unable to open the google help me out with this error which I am facing

package selenium1;

import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class selenium2 {
    public static void main(String[] args) throws Exception {

        System.out.println("hello world ");
        System.setProperty.("webdriver.firefox.marionette","/Users/bindumalini.n/Downloads/geckodriver.exe";
        WebDriver driver = new FirefoxDriver();
        driver.quit();
        driver.get("www.gmail.com");
        System.out.println("hello");
    }
}

output//

hello world Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start. Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z' System info: host: 'BLRJPT6861D', ip: 'fe80:0:0:0:148a:bc94:9bd4:8a04%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_141' Driver info: driver.version: FirefoxDriver at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:133) at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:118) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:130) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103) at selenium1.selenium2.main(selenium2.java:13) Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:48007/hub/status] to be available after 45005 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:131) ... 8 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask.get(FutureTask.java:205) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 9 more

3
try to set system propertie with 'webdriver.gecko.driver' - Infern0

3 Answers

0
votes

You used driver.quit(); before navigating, this quits this driver and closes the associated window.

Move it to the end of the script (or after the last use)

public static void main(String[] args) throws Exception {
    System.out.println("hello world ");
    System.setProperty.("webdriver.firefox.marionette","/Users/bindumalini.n/Downloads/geckodriver.exe";
    WebDriver driver = new FirefoxDriver();     
    driver.get("www.gmail.com");
    driver.quit();
    System.out.println("hello");
}
0
votes

As you are using Selenium v3.14.0 instead of webdriver.firefox.marionette you need to use GeckoDriver manadatorily as webdriver.gecko.driver.

Additionally, as you are on Mac OS X you have to download geckodriver-v0.23.0-macos.tar.gz from mozilla/geckodriver and while specifying the absolute path you need to remove the extension (i.e. .exe)

You can use the following solution:

package selenium1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class selenium2 {
    public static void main(String[] args) throws Exception {

    System.out.println("hello world ");
    System.setProperty.("webdriver.gecko.driver","/Users/bindumalini.n/Downloads/geckodriver");
    WebDriver driver = new FirefoxDriver();
    driver.get("www.gmail.com");
    System.out.println("hello");
    driver.quit();
    }
}
0
votes

Try this one hope it's helping you. This is a BrowserDynamically Selenium Code... If you still facing any issue please confirm.

package com.selenium;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.edge.EdgeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.opera.OperaDriver;

import org.testng.annotations.Test;

/** * @author mohitjaiswal * */

public class BrowserDynamically {

WebDriver driver = null;
String browser = "chrome";

(Pass here browser name like "chrome","firefox","edgeBrowser","opera","IE" as in string: which you want to open browser)

String edgePath = "/Users/mohitjaiswal/Documents/\"\n" + 
                    "+ \"My-Data/Selenium Libraries/Drivers/MicrosoftWebDriver.exe";
String chromePath = "/Users/mohitjaiswal/Documents/"
        + "My-Data/Selenium Libraries/Drivers/chromedriver";
String firefoxPath = "/Users/mohitjaiswal/Documents/"
        + "My-Data/Selenium Libraries/Drivers/geckodriver";
String opraPath = "/Users/mohitjaiswal/Documents/"
        + "My-Data/Selenium Libraries/Drivers/operadriver";
String iePath = "/Users/mohitjaiswal/Documents/"
        + "My-Data/Selenium Libraries/Drivers/IEDriverServer.exe";


public void invokeBrowser(String browserName) {

    if(browserName.equalsIgnoreCase("chrome")) {
        System.setProperty("webdriver.chrome.driver", chromePath);
        driver = new ChromeDriver();
    }else if (browserName.equalsIgnoreCase("firefox")) {
        System.setProperty("webdriver.gecko.driver", firefoxPath);
        driver = new FirefoxDriver();
    }else if (browserName.equalsIgnoreCase("edgeBrowser")) {
        System.setProperty("webdriver.edge.driver", edgePath);
        driver = new EdgeDriver();
    }else if (browserName.equalsIgnoreCase("opera")) {
        System.setProperty("webdriver.opera.driver", opraPath);
        driver = new OperaDriver();
    }else if (browserName.equalsIgnoreCase("IE")) {
        System.setProperty("webdriver.ie.driver", iePath);
        driver = new InternetExplorerDriver();
    }
}

@Test
public void invokeApplication() {
    invokeBrowser(browser);
    driver.get("https://www.google.com");
    driver.manage().window().maximize();
    driver.close();
}

}