[英]How to open the link in new tab Selenium UI automation test C#
I am writing the selenium UI tests. 我正在编写硒UI测试。 I need to open the link in new tab after I click the URL.
单击URL后,我需要在新选项卡中打开链接。 I used the below code but didn't work.
我使用了下面的代码,但是没有用。
Actions action = new Actions(WebDriver);
action.KeyDown(Keys.Control).MoveToElement(TermsOfUseLinkElement).KeyUp(Keys.Control).Click().Build().Perform();
Any other suggestions? 还有其他建议吗?
我找到了答案。
((IJavaScriptExecutor)WebDriver).ExecuteScript("window.open('" + TermsOfUseLinkElement + "','_blank');");
If you still want to stick with Actions
you can use the following solution: 如果您仍要坚持使用
Actions
,则可以使用以下解决方案:
Actions action = new Actions(WebDriver);
action.keyDown(Keys.Control).Click(TermsOfUseLinkElement).KeyUp(Keys.Control).Build().Perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.