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();

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

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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