我正在尝试在新标签页中打开链接。
Actions action = new Actions(Driver).KeyDown(Keys.Control).KeyDown(Keys.Shift).Click(FindElement(xxx).KeyUp(Keys.Control).KeyUp(Keys.Shift);
action.Build().Perform();
此代码在新标签页中打开链接,同时打开另一个空白窗口
action.ContextClick(FindElement(xxx).SendKeys(Keys.ArrowDown).SendKeys(Keys.Enter).Build().Perform();
这将在新窗口而不是新标签页中打开链接
答案 0 :(得分:0)
所以您需要做的是首先使用JS执行器打开一个新标签页:
((JavascriptExecutor)driver).executeScript("window.open()");
或
((JavascriptExecutor)driver).executeScript("window.open('the new link here', '_blank')");
如果您未使用secon方法,请继续执行以下操作:切换到新窗口并导航到链接
driver.switchTo().window(here the window handle);
driver.get("here is the link");