Home > OS >  How To Set ChromeOptions (or goog:ChromeOptions) for Selenium::Chrome in Perl
How To Set ChromeOptions (or goog:ChromeOptions) for Selenium::Chrome in Perl

Time:03-18

In Python, I could easily change the browser "navigator.webdriver" property to false, when using the local chromedriver with my local Chrome browser.

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(chrome_options=options)
driver.get([some url])

After the above, in the Chrome browser console, navigator.webdriver would show "false".

But I do not know how to translate the above to Perl. The following code would still leave the navigator.webdriver as "true". So how do I implement the Python code above in Perl? Is it possible (ideally without using the remote stand-alone selenium server)?

use strict;
use warnings;
use Selenium::Chrome;
my $driver = Selenium::Chrome->new(
   custom_args => '--disable-blink-features=AutomationControlled' );
$driver->get([some url]);

Any help would be greatly appreciated!

CodePudding user response:

Need to use extra_capabilities with goog:chromeOptions

my $drv = Selenium::Chrome->new(
     'extra_capabilities' => {
         'goog:chromeOptions' => {
             prefs => { ... },
             args => [ 
                 'window-position=960,10', 'window-size=950,1180', # etc   
                 'disable-blink-features=AutomationControlled'
             ]
         }
     }
);

(I don't know how disable-blink-features relates to that "navigator.webdriver")

For the list of attributes available in the constructor, along with the extra_capabilities, see Selenium::Remote::Driver, from which Selenium::Chrome inherits.

For Chrome-specific capabilities see "Recognized capabilities" in chromedriver, and more generally see Selenium documentation and W3C WebDriver standard.


Specifically

  • Related