如何在 Perl 中为 Selenium::Chrome 设置 ChromeOptions(或 goog:ChromeOptions)

Sha*_*ang 4 python perl selenium-chromedriver chrome-options

在 Python 中,当在本地 Chrome 浏览器中使用本地 chromedriver 时,我可以轻松地将浏览器“navigator.webdriver”属性更改为 false。

from selenium import webdriver

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

完成上述操作后,在Chrome浏览器控制台中,navigator.webdriver会显示“false”。

但我不知道如何将上面的内容翻译成Perl。以下代码仍会将 navigator.webdriver 保留为“true”。那么如何在 Perl 中实现上面的 Python 代码呢?是否可能(理想情况下不使用远程独立硒服务器)?

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

任何帮助将不胜感激!

zdi*_*dim 5

需要extra_capabilities配合使用goog:chromeOptions

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

(我不知道disable-blink-features与“ navigator.webdriver ”有什么关系)

\n

有关构造函数中可用属性的列表以及extra_capabilities,请参阅Selenium::Remote::Driver , Selenium::Chrome 继承自该Selenium::Remote::Driver 。

\n

对于特定于 Chrome 的功能,请参阅chromedriver 中的“公认的功能”,更一般的情况请参阅Selenium 文档W3C WebDriver 标准\xe2\x80\xa0

\n
\n

\xe2\x80\xa0具体来说

\n\n