Selenium C#打开“新建"选项卡CTRL + T不适用于CHROME [英] Selenium C# Open New Tab CTRL+T Not working with CHROME

查看:151
本文介绍了Selenium C#打开“新建"选项卡CTRL + T不适用于CHROME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main()
{
    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl("http://google.com");
    IWebElement body = driver.FindElement(By.TagName("body"));

    body.SendKeys(Keys.Control + "t");

}

这是我试图用来打开新标签页且无法正常工作的代码,我什么也没有收到任何错误,驱动程序打开了Google,仅此而已.... 我搜索了很多东西,发现很多教程,甚至是视频,其中的人们都使用完全相同的代码,并且对他们有用.

我尝试将Keys.Shift +"t"发送到搜索字段,并且可以正常工作,它在该字段中写了一个大写字母T

我也尝试过

Actions act = new Actions(driver);
act.KeyDown(Keys.Control).SendKeys("t").Perform();

它仍然不起作用,但是如果我将Keys.Control更改为它编写的Keys.Shift,它似乎也没有涉及Keys.Control的东西!

我已经尝试使用IE驱动程序运行代码,并且该代码可以在那运行,它可以打开新标签页,但是不能在Chrome上打开新标签页?

解决方案

感谢您的回答!我是用JavaScript完成的.​​

((IJavaScriptExecutor)driver).ExecuteScript("window.open();");

static void Main()
{
    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl("http://google.com");
    IWebElement body = driver.FindElement(By.TagName("body"));

    body.SendKeys(Keys.Control + "t");

}

This is the code that I am trying to use to open a new tab and its not working, I am not getting any errors nothing, the driver opens Google and thats all.... I have searched a lot and found many tutorials even videos where people are using the exact same code and it works for them, but for me it doesnt and I can't figure it out...

I tried sending Keys.Shift + "t" to the search field and it works, it writes a capital T in the field

I have also tried

Actions act = new Actions(driver);
act.KeyDown(Keys.Control).SendKeys("t").Perform();

And it still does not work, but again if I change Keys.Control to Keys.Shift it writes, seems like nothing that involves Keys.Control is working!!

Edit: I have tried running the code with a IE Driver and it worked there, it opens new tab, but it does not open new tabs on Chrome?

解决方案

Thanks for the answers! I did it with JavaScript.

((IJavaScriptExecutor)driver).ExecuteScript("window.open();");

这篇关于Selenium C#打开“新建"选项卡CTRL + T不适用于CHROME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆