tebeka / selenium

Selenium/Webdriver client for Go
MIT License
2.51k stars 410 forks source link

Disable "Chrome is being controlled by automated test software" info bar #233

Open xceejay opened 3 years ago

xceejay commented 3 years ago

I realized that options like "--disable-infobars" are deprecated and therefore does not hide the infobar, there's a work around for disabling the infobar in chrome's experimental options, which can be referenced here https://stackoverflow.com/a/43145088 . It seems the experimental feature is not available in golangs selenium port

x-Xymos commented 3 years ago

This can be achieved with the following capability switch

caps = selenium.Capabilities{"browserName": "chrome",
    "chromeOptions": map[string]interface{}{ 
        "excludeSwitches": [1]string{"enable-automation"}, 
    }, 
} 
xceejay commented 3 years ago

thank you, that worked

akingscote commented 3 years ago

hmm it dosent seem to work if there are chrome capabilities as well :/

x-Xymos commented 3 years ago

@akingscote what do you mean by that, can you post a code example

akingscote commented 3 years ago

Sure, so the following works as expected:

import (
    "fmt"
    "os"
    "github.com/tebeka/selenium"
)
...
    caps := selenium.Capabilities{
        "browserName": "chrome",
        "chromeOptions": map[string]interface{}{ 
            "excludeSwitches": [1]string{"enable-automation"}, 
        },
    }

I dont have that automation banner, but unfortunately the window is quite small. I'd like it to be maximised.

In extending functionality with chrome capabilities, it seems to ignore the selenium capabilities.

import (
    "fmt"
    "os"
    "github.com/tebeka/selenium"
    "github.com/tebeka/selenium/chrome"
)
...
    caps := selenium.Capabilities{
        "browserName": "chrome",
        "chromeOptions": map[string]interface{}{ 
            "excludeSwitches": [1]string{"enable-automation"}, 
        },
    }

    chromeCaps := chrome.Capabilities{
        Path: "",
        Args: []string{
            "--headless",
            "--start-maximized",
            "--window-size=1200x600",
            "--no-sandbox",
            "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
            "--disable-gpu",
            "--disable-impl-side-painting",
            "--disable-gpu-sandbox",
            "--disable-accelerated-2d-canvas",
            "--disable-accelerated-jpeg-decoding",
            "--test-type=ui",
        },
    }
    caps.AddChrome(chromeCaps)

It seems i can use one or the other, but not both. Unless im missing something...

x-Xymos commented 3 years ago

@akingscote you can add args in the following way ( I haven't included them all from your example )

import (
    "fmt"
    "os"
    "github.com/tebeka/selenium"
)
...
    caps := selenium.Capabilities{
        "browserName": "chrome",
        "chromeOptions": map[string]interface{}{ 
            "excludeSwitches": [1]string{"enable-automation"}, 
             "args":            []string{"--headless", "--start-maximized", "--no-sandbox"},
            },
    }
akingscote commented 3 years ago

fantastic thats got it thank you very much. My example was pretty bad, because --headless contradicts --start-maximized, but adding the args directly to the chromeOptions instead of separately has done the job. Thanks for your help!