Mozilla FirefoxDownload WebDriver jar files for Mozilla Firefox. Add all jar files in your project
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MozillaFirefoxbrowser {
public static void main(String args[]) {
// Initialize driver
WebDriver dr = new FirefoxDriver();
//Maximize browser window
dr.manage().window().maximize();
//Go to URL
dr.get("http://www.google.com");
//Set timeout
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//close firefox browser
dr.close();
}
}
Internet ExplorerDownload Internet Explorer Driver Server
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class InternetExplorerBrowser {
public static void main(String args[]) {
//set the system property for Internet Explorer
//System.setProperty("webdriver.ie.driver", "Location of IE Driver");
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
// Initialize IE driver
WebDriver driver = new InternetExplorerDriver();
//Maximize browser window
driver.manage().window().maximize();
//Go to URL
driver.get("http://www.google.com");
//close Internet Explorerbrowser
driver.quit();
}
}
<center>
Google ChromeDownload Chrome Driver Server
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Chromebrowser {
public static void main(String args[]) {
//set the system property for Chrome
//System.setProperty("webdriver.chrome.driver", "Location of Chrome Driver");
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
// Initialize IE driver
WebDriver driver = new ChromeDriver();
//Maximize browser window
driver.manage().window().maximize();
//Go to URL
driver.get("http://www.google.com");
}
}
SafariDownload Selenium WebDriver for Safari. Add jar file in your project
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Safaribrowser {
public static void main(String args[]) {
// Initialize driver
WebDriver dr = new SafariDriver();
//Maximize browser window
dr.manage().window().maximize();
//Go to URL
dr.get("http://www.google.com");
//Set timeout
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//close Safari browser
dr.quit();
}
}
OperaDownload Selenium WebDriver for Opera. Add jar file in your project import com.opera.core.systems.OperaDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Operabrowser {
public static void main(String args[]) {
//System.setProperty("webdriver.ie.driver", "Location of opera Driver");
System.setProperty("webdriver.ie.driver", "operadriver.exe");
// Initialize Opera driver
WebDriver driver = new OperaDriver();
//Maximize browser window
driver .manage().window().maximize();
//Go to URL
dr.get("http://google.com");
//Set timeout
driver .manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//close Oper browser
driver .quit();
}
}
HtmlUnit Driver
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Htmlunit {
public static void main(String args[]) {
// Initialize driver
WebDriver dr = new HtmlUnitDriver();
//Go to page
dr.get("http://www.google.com");
//get page title
System.out.println("Title =: " + dr.getTitle());
//get page url
System.out.println("URL =: " + dr.getCurrentUrl());
//close Htmlunit
dr.close();
}
}
The code for Opera is not working for me. Exception: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.opera.driver system property; for more information, see https://github.com/operasoftware/operachromiumdriver. The latest version can be downloaded from https://github.com/operasoftware/operachromiumdriver/releases
ReplyDeleteUse "webdriver.opera.driver" instead of "webdriver.ie.driver"
DeleteTrusted antivirus programming must be fit for shielding your PC from every single conceivable risk, for example, infections, Trojans, spyware, secret key stealers, phishing assaults, malware, and spam and so on. http://how-to-remove.org/malware/browser-hijacker-removal/easyopenweb-com-removal/
ReplyDeleteWhenever I try to run the Opera code, even with the change, webdriver.opera.driver, Opera opens & crashes at the same time. Any ideas?
ReplyDeleteSafari browser does not support the following command,
ReplyDeletedriver.manage().window().maximize();
Do we have any workaround by any chance?