0% found this document useful (0 votes)
3 views1 page

Selenium WebDriver Example in Java

The document is a Java program that uses Selenium WebDriver to automate browser testing. It sets up the ChromeDriver to run tests on Google, specifically to open the Gmail page and print its title. The code also includes commented-out sections for running tests on Firefox and Internet Explorer, but only Chrome is executed in the current state.

Uploaded by

Akshata Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Selenium WebDriver Example in Java

The document is a Java program that uses Selenium WebDriver to automate browser testing. It sets up the ChromeDriver to run tests on Google, specifically to open the Gmail page and print its title. The code also includes commented-out sections for running tests on Firefox and Internet Explorer, but only Chrome is executed in the current state.

Uploaded by

Akshata Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package softwareTesting;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Program2 {

public static void main(String[] args) {

// Paths to drivers (update according to your system)


[Link]("[Link]", "C:\\Users\\[Link]\\
Desktop\\chromedriver-win64\\[Link]");
//[Link]("[Link]", "C:\\drivers\\
[Link]");
//[Link]("[Link]", "C:\\drivers\\
[Link]");

// Run on Chrome
[Link]("=== Running on Chrome ===");
WebDriver chrome = new ChromeDriver();
testGoogle(chrome);

// Run on Firefox
//[Link]("=== Running on Firefox ===");
// WebDriver firefox = new FirefoxDriver();
// testGoogle(firefox);

// Run on Internet Explorer


// [Link]("=== Running on Internet Explorer ===");
// WebDriver ie = new InternetExplorerDriver();
// testGoogle(ie);
}

public static void testGoogle(WebDriver driver) {


try {
[Link]("[Link]

// Click Gmail link


[Link]([Link]("Gmail")).click();

// Print the title of Gmail page


[Link]("Opened page title: " + [Link]());
} catch (Exception e) {
[Link]();
} finally {
[Link](); // close browser
}
}
}

You might also like