3

I am trying to open new tab with selenium webdriver for golang using control+t kyes following example for another languages. But cannot figure out how to send control.

My attempts with "ctrl t", "control t", "Control t" failed.

package main

import (
    "github.com/fedesog/webdriver"
)

func main() {
    chromeDriver := webdriver.NewChromeDriver("/Users/maks/Downloads/chromedriver")
    err := chromeDriver.Start()
    if err != nil {
        panic(err)
    }
    desired := webdriver.Capabilities{"Platform": "Mac"}
    required := webdriver.Capabilities{}
    session, err := chromeDriver.NewSession(desired, required)
    if err != nil {
        panic(err)
    }

    session.Url("http://stackoverflow.com")
    el, err := session.FindElement("tag name", "body")
    if err != nil {
        panic(err)
    }
    err = el.SendKeys("ctrl t")
    if err != nil {
        panic(err)
    }
}
Community
  • 1
  • 1
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166

2 Answers2

0

For me it worked using the selenium pkg of go.

elem.SendKeys(selenium.ControlKey + "a")

Browserstack seems to be receiving CONTROLa Perhaps using "CONTROLa" works? I don't know but selenium works fine so I recommend using it.

-2

You did not tag what language that is, but I'm guessing it's C#

Here's how I accomplish it in java:

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
  • This post is almost two years old. While I can see downvoting it based on the question's current content, I am fairly certain that when I answered the question, there was no language tag (I see now there's a go tag) and there was definitely no code shown. Three downvotes for a correct answer with the caveat that the language was not specified is a tad severe in my opinion. – Bill Hileman Dec 23 '18 at 03:53