Selenium C# Open New Tab CTRL+T Not working with CHROME

后端 未结 4 1416
太阳男子
太阳男子 2021-01-12 00:14
static void Main()
{
    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl(\"http://google.com\");
    IWebElement body = driver.FindElement(By.T         


        
相关标签:
4条回答
  • 2021-01-12 00:30

    Looks like it's a "feature" of the chrome driver.

    https://bugs.chromium.org/p/chromedriver/issues/detail?id=581

    This is a limitation in the way we simulate keyboard input in ChromeDriver. Keys get sent directly to the render process, bypassing the browser process. So any keyboard shortcut handlers in the browser process will not be invoked by sendKeys().

    0 讨论(0)
  • 2021-01-12 00:32

    Thanks for the answers! I did it with JavaScript.

    ((IJavaScriptExecutor)driver).ExecuteScript("window.open();");
    
    0 讨论(0)
  • 2021-01-12 00:41

    Try this

    driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
    driver.SwitchTo().Window(driver.WindowHandles.Last());
    driver.Navigate().GoToUrl("http://www.google.com")
    
    0 讨论(0)
  • 2021-01-12 00:46

    If your on a mac, use Keys.Command instead of Keys.Control:

    body.SendKeys(Keys.Command + "t");
    
    0 讨论(0)
提交回复
热议问题