我想知道如何在使用selenium时禁用javascript,以便我可以测试服务器端验证.
我找到了这篇文章,但我不知道该怎么做.就像我制作这个javascript文件那么?
http://thom.org.uk/2006/03/12/disabling-javascript-from-selenium/
我正在无头地使用 Chrome。
我尝试设置--disable-javascript命令行参数。
我尝试使用实验选项:
$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);
Run Code Online (Sandbox Code Playgroud)
到目前为止,这两个都不起作用。
如何使用 Facebook PHP Webdriver 在 Chrome 中禁用 javascript?
这是一个检查 JavaScript 是否启用的测试:
$this->driver->get('https://www.whatismybrowser.com/detect/is-javascript-enabled');
return [
$this->driver->getTitle(),
$this->driver->findElement(WebDriverBy::cssSelector('.detected_result'))->getText()
];
Run Code Online (Sandbox Code Playgroud) 如何使用python在Selenium的Chrome驱动程序中禁用Java Script