selenium icon indicating copy to clipboard operation
selenium copied to clipboard

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

Open xceejay opened this issue 3 years ago • 7 comments

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

xceejay avatar Mar 15 '21 11:03 xceejay

This can be achieved with the following capability switch

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

x-Xymos avatar May 07 '21 20:05 x-Xymos

thank you, that worked

xceejay avatar May 07 '21 20:05 xceejay

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

akingscote avatar May 12 '21 08:05 akingscote

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

x-Xymos avatar May 12 '21 09:05 x-Xymos

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...

akingscote avatar May 12 '21 09:05 akingscote

@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"},
            },
    }

x-Xymos avatar May 12 '21 09:05 x-Xymos

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!

akingscote avatar May 12 '21 09:05 akingscote