如何强制Selenium在新窗口中打开链接?

CHE*_*HKA 3 java selenium google-chrome

我需要在新的Chrome窗口中打开网页上的链接.已经有一个问题, 但这似乎是RC.我试过 driver.getUserWindow().open("http....."); 但它不起作用.可能有办法迫使Chrome为所有链接执行此操作吗?理想情况下,我想知道如何强制驱动程序在新窗口中打开链接.(我使用的是java和OS Windows 7

Vin*_*nay 6

您可以使用Actions类来执行此操作.

Actions act = new Actions(driver);
WebElement onElement = Your element on which action has to be performed;
act.contextClick(onElement).perform();
act.sendKeys("w").perform();  // If you want the link to open in new tab then use T instead of w
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.快乐的编码.