我正在使用Selenium Webdriver和Java,正在进行Web浏览器调用,我需要登录两个不同的帐户。 步骤进行:
有没有办法同时使用Selenium WebDriver运行两个不同的浏览器?
注意:
我试过这个,但第一个浏览器关闭,打开一个新的 浏览器实际:Chrome浏览器,然后打开新的Chrome浏览器(在 隐身),但仍然是第一个Chrome浏览器关闭。
我启动了另一个驱动程序来打开新的Chrome浏览器。
public static void main (String[] args){
WebDriver driver1 = new ChromeDriver();
driver1.manage().window().maximize();
driver1.get(baseUrl);
WebDriverWait wait = new WebDriverWait(driver1,30);
String win1 = driver1.getWindowHandle();
driver1.switchTo().window(win1);
WebElement emailField = driver1.findElement(By.id("email"));
emailField.sendKeys(data1);
WebElement passField = driver1.findElement(By.id("password"));
passField.sendKeys(data2);
WebElement passField = driver1.findElement(By.id("loginBtn")).click();
WebDriver driver2 = new ChromeDriver();
driver2.manage().window().maximize();
driver2.get(baseUrl);
WebDriverWait wait = new WebDriverWait(driver2,30);
String win2 = driver2.getWindowHandle();
driver2.switchTo().window(win2);
WebElement emailField = driver2.findElement(By.id("email"));
emailField.sendKeys(data1);
WebElement passField = driver2.findElement(By.id("password"));
passField.sendKeys(data2);
WebElement passField = driver2.findElement(By.id("loginBtn")).click();
driver1.switchTo().window(win1);
WebElement dialField = driver1.findElement(By.id("dial"));
dialField.sendKeys(number);
WebElement callIcon = driver1.findElement(By.id("call")).click();
driver2.switchTo().window(win2);
WebElement answerIcon = driver2.findElement(By.id("answer")).click();
Thread.sleep(3000);
WebElement endCall = driver2.findElement(By.id("hangup")).click();
driver1.close();
driver2.close();
driver1.quit();
driver2.quit();
}