How to open a web page using Selenium WebDriver?

How to open a web page using Selenium WebDriver?

1. Create a JAVA Class.

2. Enter class name and Save it.

3. Create a method inside the class. In my case I have created startTest().

3. Include @Test annotation.

4. Use the help icon to fix the issue by importing “import org.junit.Test;”.

5. Use the below code to open a web page.

WebDriver wd = new FirefoxDriver();
wd.get("http://www.google.com");

6. Fix the errors by importing the below

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

Sample Code:

package seleniumPackage;

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

public class OpenWebPage {
	
	
	@Test
	public void openSite() {

		WebDriver wd = new FirefoxDriver();
		wd.get(
			"http://www.google.com"
		);
		
	}

}

7. Run it, so that it will open the page.

Leave a Reply