0

I am using the below code for launching the firefox browser but am getting the error as follow. please help me in resolving the issue.

Code:

public class FirstClass {
    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver(); 

        try {
            driver.wait(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        driver.get("www.Google.com");
        driver.close();
    }
}

Error:

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Bad request

Command duration or timeout: 5.81 seconds

Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'

System info: host: 'ATUMKURX-MOBL', ip: '10.223.181.206', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74'

Driver info: org.openqa.selenium.firefox.FirefoxDriver

content of host file:

localhost name resolution is handled within DNS itself.

127.0.0.1       localhost

::1             localhost

127.0.0.1       LIUYUNKX-MOBL.gar.corp.intel.com # LMS GENERATED LINE
halfer
  • 19,824
  • 17
  • 99
  • 186
Amith
  • 1
  • 2

4 Answers4

0

Try this

WebDriver driver = new FirefoxDriver()
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://www.google.com");
driver.close();
Haxor
  • 2,306
  • 4
  • 16
  • 18
  • Used the above suggested code but still issue remains the same. – Amith May 19 '16 at 07:14
  • 1
    This exception is thrown when you have more than 1 entry of 127.0.0.1. See the issue here - https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/3280 – Haxor May 19 '16 at 07:20
  • i have refered this but i have only one entry on 127.0.0.1 in the host file, the same i have shared in my question – Amith May 19 '16 at 08:25
  • @Amith - 127.0.0.1 localhost 127.0.0.1 LIUYUNKX-MOBL.gar.corp.intel.com # LMS GENERATED LINE Above are the two entries. – Haxor May 19 '16 at 08:28
  • Thanks a lot, issue got resolved. left the last line of the host file was not commented. – Amith May 19 '16 at 08:34
0

Instead of driver.wait(5000); use Thread.sleep(5000);

Below code is working for me :-

  try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
    driver.get("www.Google.com");
    driver.close();
    System.out.println("Edd");

}

While using Thread is not recommended you can use implicitlyWait also:-

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

implicitlyWait wait through out your script for every element selenium looking for

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0
WebDriver driver = new FirefoxDriver()
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.com");
driver.quit();

if same issue exits, please upgrade selenium jar (http://www.seleniumhq.org/download/) to latest, and updat`enter code here`e firefox to latest and try.. 
  • Selenium version is new 2.53.0 and hopefully there is something to do with host file. have a look at the content of the host file which i have shared and suggest me if there is anything to update? – Amith May 19 '16 at 08:21
  • Please check in host file, and all content should be commented. and save and run again # 127.0.0.1 localhost #::1 localhost #127.0.0.1 LIUYUNKX-MOBL.gar.corp.intel.com # LMS GENERATED LINE – Manjunatha.N May 19 '16 at 08:23
  • Thanks a lot, issue got resolved. left the last line of the host file was not commented. And after the run got success full am getting the below in the console, could you please help me in knowing what is this? "Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true" – Amith May 19 '16 at 08:33
  • What project are you running? Are there problems/symptoms beyond what you're seeing in the console? What version of Eclipse are you using? Basically those message will not be affecting ur selenium test... do you have any other os in your machine – Manjunatha.N May 19 '16 at 08:42
  • Am just setting up my for new project which was supposed to start in few months. there are no other problems in the console which i shared. Am using "Luna Service Release 2 (4.4.2)" esclipse – Amith May 19 '16 at 08:45
0

Below is the Answer:

Last line of the host file was not commented.

After commenting the last line the issue got resolved.

Amith
  • 1
  • 2