怎么通过selenium实现在新窗口打开链接
1个回答
展开全部
下面代码是在新的tab里打开链接
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL.toString()+"n"); // send CTRL+n to create a new tab
// switch to new created TAB
Object[] windowhandles = driver.getWindowHandles().toArray();
Object newWindowHandle = windowhandles[windowhandles.length-1];
driver.switchTo().window((String) newWindowHandle);
driver.get(url);
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL.toString()+"n"); // send CTRL+n to create a new tab
// switch to new created TAB
Object[] windowhandles = driver.getWindowHandles().toArray();
Object newWindowHandle = windowhandles[windowhandles.length-1];
driver.switchTo().window((String) newWindowHandle);
driver.get(url);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询