Selenium: Opening Firefox, IE and Chrome Browsers
Firefox:
FirefoxDriver oFFdriver=new
FirefoxDriver();
oFFdriver.get("http://www.google.com");
JOptionPane.showMessageDialog(null,
"Done");
OR
-------------------------Code to Set Profile-------------------
ProfilesIni listprofile=new ProfilesIni();
FirefoxProfile profile=listprofile.getProfile("default");
WebDriver driver=new FirefoxDriver(profile);
driver.get("http://www.google.com");
----------------------------------------------------------------------
Internet Explorer
Note:
1. You will need IE Driver for Selenium.
2. Follow the link below and download the
driver. http://code.google.com/p/selenium/downloads/list
3. Extract it into the folder and use the path
inside the code
System.setProperty("webdriver.ie.driver","Your_Path//IEDriverServer.exe");
WebDriver webdriver = new InternetExplorerDriver();
webdriver.manage().window().maximize();
webdriver.get("http://www.usatoday.com");
Chrome :
Note:
1. You will need Chrome Driver for Selenium.
2. Follow the link below and download the
driver. https://code.google.com/p/chromedriver/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount+Release
3. Extract it into the folder and use the path
inside the code
----------------Simple Code-----------------------------------------
System.setProperty("webdriver.chrome.driver","Path of Chrome driver");
//while giving path use "\\" instead of "\"
WebDriver driver=new ChromeDriver();
driver.get("http://wikipedia.org");
---------------------------------------------------------------------------
OR
------------Code to set profile in Chrome -------------------------
final String userProfile= "Your default -UserDate path in Chrome"
//"C:\\Users\\deepakj\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\";
ChromeOptions
options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
System.setProperty("webdriver.chrome.driver","http://www.usatoday.com");
webdriver =
new ChromeDriver(options);
webdriver.manage().window().maximize();
webdriver.get(url);
----------------------------------------------------------------------------
ok thanks for this post it's quite informative and I have learned new things.
ReplyDeletekajal agarwal hot