简体   繁体   English

如何在新选项卡中打开链接Selenium UI自动化测试C#

[英]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.

相关问题 在新标签页硒C#中打开链接 - Open link in new tab selenium c# 如何单击链接并在新选项卡中打开它 Selenium WebDriver C# - How to click a link and open it in a new tab Selenium WebDriver C# 如何在NUnit测试框架上使用Selenium C#在新的Chrome选项卡上打开URL - How to open a url on a new Chrome Tab using selenium C# over NUnit test framework Selenium + C#单击链接时如何切换Firefox的另一个选项卡,它将在另一个选项卡中打开? - Selenium + C# How to switch another Tab of Firefox when click a link and it will open in another tab? 如何使用 Selenium 和 C# 修复测试自动化代码? - How to fix test automation code using Selenium with C#? C#Selenium firefox打开新选项卡不起作用 - c# selenium firefox open new tab is not working 如何通过单击asp.net c#中的链接按钮来打开带有会话的新标签? - how to open a new tab with session by clicking link button in asp.net c#? 如何通过Web浏览器控件在新的浏览器选项卡中打开url(显示具有链接的PDF)C# - How to open url in new browser tab from Web browser control (displaying PDF having a link) c# 如何通过 Unity 使用 WebGL/C# 在新选项卡上打开链接? - How to open a link on a new tab using WebGL/C# through Unity? c# 如何在 selenium 4.4.3 中找到为用户打开的选项卡 - c# how to find which tab is open for user in selenium 4.4.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM