How to open bowser in selenium
,
To open a browser in Selenium, you need to create an instance of the WebDriver class and use its methods to navigate to a URL. Here's an example of how to open the Google Chrome browser using Selenium WebDriver:
public class OpenBrowserExample {
public static void main(String[] args) {
// Set the path of the ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
// Create an instance of the ChromeDriver
WebDriver driver = new ChromeDriver();
// Navigate to a URL
driver.get("https://www.google.com");
// Close the browser
driver.quit();
}
}
In this example, we first set the path of the ChromeDriver executable using the System.setProperty() method. Then, we create an instance of the ChromeDriver by calling its constructor. Finally, we use the get() method of the WebDriver class to navigate to a URL, and the quit() method to close the browser.
Note that you need to download the appropriate driver executable file for the browser you want to automate and set its path using System.setProperty(). In this example, we have used the ChromeDriver executable file for Google Chrome.
Related Posts:
education
Subscribe to:
Post Comments (Atom)











0 comments: