To open two Chrome windows using Selenium in Java, you can use the following code:
```java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class TwoChromeWindows {
public static void main(String[] args) {
// create first instance of Chrome
ChromeOptions chromeOptions1 = new ChromeOptions();
chromeOptions1.addArguments("--start-maximized");
WebDriver driver1 = new ChromeDriver(chromeOptions1);
// create second instance of Chrome
ChromeOptions chromeOptions2 = new ChromeOptions();
chromeOptions2.addArguments("--start-maximized");
WebDriver driver2 = new ChromeDriver(chromeOptions2);
}
}
```
This code will create two instances of Chrome, each running with its own `WebDriver` object. The `--start-maximized` argument maximizes the window when it is launched. You can modify the options to suit your specific needs.
Make sure to download and install the ChromeDriver executable and add it to your system's PATH environment variable before running this code. You can download the ChromeDriver executable from the official website: https://sites.google.com/a/chromium.org/chromedriver/downloads.
0 comments:
Post a Comment