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

Selenium WebDriver Google Search Automation

The document is a Java program that uses Selenium WebDriver to automate a Google search for 'Software Testing'. It opens the Chrome browser, inputs the search term, waits for the results, clicks the first result, and prints the title of the opened page. Finally, it ensures the browser is closed regardless of any exceptions that may occur.

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)
15 views1 page

Selenium WebDriver Google Search Automation

The document is a Java program that uses Selenium WebDriver to automate a Google search for 'Software Testing'. It opens the Chrome browser, inputs the search term, waits for the results, clicks the first result, and prints the title of the opened page. Finally, it ensures the browser is closed regardless of any exceptions that may occur.

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 Program3 {


public static void main(String[] args) {
// Set path to [Link] (update path according to your system)
[Link]("[Link]", "C:\\Users\\[Link]\\
Desktop\\chromedriver-win64\\[Link]");

// Launch Chrome browser


WebDriver driver = new ChromeDriver();

try {
// Step 1: Open Google
[Link]("[Link]

// Step 2: Locate the search box and enter keyword


WebElement searchBox = [Link]([Link]("q"));
[Link]("Software Testing");
[Link]([Link]); // press Enter

// Step 3: Wait a bit for results to load


[Link](10000); // better to use WebDriverWait in real projects

// Step 4: Click the first visible search result link


WebElement firstResult = [Link]([Link]("h3"));
[Link]();

// Step 5: Print the title of the opened page


[Link]("Opened page title: " + [Link]());

} catch (Exception e) {
[Link]();
} finally {
// Close the browser
[Link]();
}
}
}

You might also like