How to disable Javascript in Chrome (-headless) using Webdriver

I use Chrome without a problem.

I tried to set the command line argument --disable-javascript.

I tried using experimental options:

        $options->setExperimentalOption('prefs', [
            'profile.managed_default_content_settings.javascript' => 2//this does not work
            //,'profile.default_content_setting_values.javascript' => 2//this does not work, too
        ]);

        $capabilities = DesiredCapabilities::chrome();
        $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);

From now on, these two do not work.

How to disable javascript in Chrome using PHP PHP Webdriver?

Here is a test to check if JavaScript is enabled:

        $this->driver->get('https://www.whatismybrowser.com/detect/is-javascript-enabled');
        return [
            $this->driver->getTitle(),
            $this->driver->findElement(WebDriverBy::cssSelector('.detected_result'))->getText()
        ];
+4
source share
2 answers

You can disable Javascript execution by setting one of these settings:

"webkit.webprefs.javascript_enabled": false
"profile.content_settings.exceptions.javascript.*.setting": 2
"profile.default_content_setting_values.javascript": 2
"profile.managed_default_content_settings.javascript": 2

But it is currently not supported without a headset , since this mode does not load settings and there is no one associated with this function.

, JavaScript Selenium, - , . . . , <noscript> ( , JavaScript ). - innerText execute_script get_attribute.

+1

. http://yizeng.me/2014/01/08/disable-javascript-using-selenium-webdriver/

. JavaScript , , ChromeDriver. , , . , .      WontFix - ChromeDriver ( WebDriver, ), JavaScript .

+3

Source: https://habr.com/ru/post/1688562/


All Articles