Can Twist use a browser that is open?



  • Avatar
    Prateek Kumar Baheti

    Twist currently cannot use an already open browser. The browser instance needs to be launched by twist. 

    Comment actions Permalink
  • Avatar
    Gennadiy Kasyan

    Theoretically, you can attach with a RemoteWebDriver to already opened IE if you have the session id.

    Please have a look on on GitHub and the Selenium source code.

    You need to modify, override  protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) in a similar way.

    JS execution will not work if you attach to an open IE.

    To enable it, add to the

    private Capabilities capabilities

    public Capabilities getCapabilities() {
    return capabilities;

    private boolean isJavascriptEnabled() {
    return capabilities.isJavascriptEnabled();

    public Object executeScript(String script, Object... args) {
    if (!capabilities.isJavascriptEnabled()) {
    throw new UnsupportedOperationException(
    "You must be using an underlying instance of WebDriver that supports executing javascript");

    // Escape the quote marks
    script = script.replaceAll("\"", "\\\"");

    Iterable<Object> convertedArgs = Iterables.transform(
    Lists.newArrayList(args), new WebElementToJsonConverter());

    Map<String, ?> params = ImmutableMap.of(
    "script", script,
    "args", Lists.newArrayList(convertedArgs));

    return execute(DriverCommand.EXECUTE_SCRIPT, params).getValue();

    Comment actions Permalink

Please sign in to leave a comment.