Selenium WebDriver example code in Java for Chrome

1 Answers
Answered by suresh

Selenium WebDriver example code in Java for Chrome:

To automate web testing using Selenium WebDriver in Java for Chrome browser, you can use the following example code:

```java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ChromeAutomation {
public static void main(String[] args) {
// Set the path to chromedriver executable
System.setProperty("webdriver.chrome.driver", "path_to_chromedriver_executable");

// Initialize Chrome driver
WebDriver driver = new ChromeDriver();

// Open the website
driver.get("https://www.example.com");

// Perform testing actions
// For example, click on a button
driver.findElement(By.id("buttonId")).click();

// Close the browser
driver.quit();
}
}
```

Focus Keyword: Selenium WebDriver example code Java Chrome

This sample code demonstrates how to set up Selenium WebDriver for Chrome in a Java environment, open a webpage, perform an action, and then close the browser. Remember to replace `"path_to_chromedriver_executable"` with the actual path to your chromedriver executable file. For detailed documentation and further customization, refer to the Selenium official website.

Answer for Question: Selenium WebDriver example code in Java for Chrome