1

enter image description here

I am trying to configure Selenium WebDriver with Eclipse IDE. While running my code I am getting java exception has occurred error. How to fix this?

import java.io.File;
import java.io.IOException;

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


public class Test {


    static WebDriver driver1=new ChromeDriver();
    String user="rutvisoni"; 
    String pass="12Abcd";

    public void setup() throws IOException
    {
        driver1.manage().window().maximize();
        driver1.get("http://example.com");

        //File inputFile = new ClassPathResource("E:\\Selenium Jar\\chromedriver.exe").getFile();
        System.setProperty("webdriver.chrome.driver","E:\\Selenium Jar\\chromedriver.exe");

    }


    public static void main(String args[]) throws IOException
    {
        Test t1=new Test();
        t1.setup();

    }
}
  • Have you configured the environment variable path for JAVA in your computer? – IAmMilinPatel Nov 21 '16 at 10:09
  • yes Configured the environment variable path for JAVA – Rutvi Soni Nov 21 '16 at 10:12
  • Would you share your code so that people here can understand the problem and try to figure out a solution? – IAmMilinPatel Nov 21 '16 at 10:13
  • Please check browser version.Is it compitable? – Vasim Shaikh Nov 21 '16 at 10:26
2

You are initializing chrome in a wrong way. In your code you have maximized browser and called the URL, before even setting up the chrome profile. You can give a try to below code:

System.setProperty("webdriver.chrome.driver", "E:\\Selenium Jar\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--start-maximized");
            driver = new ChromeDriver();

            driver1.manage().window().maximize();
            driver1.get("http://example.com");

And please remove the code line mentioned below from your code:

static WebDriver driver1=new ChromeDriver();

If you still face same exception, please share the exception details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.