【发布时间】:2017-11-02 11:07:42
【问题描述】:
我正在尝试执行 javascript 作为测试的一部分。
下面是我的 chrome 驱动设置
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("headless");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--reduce-security-for-testing");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
driver.get("https://samplesite.com/");
我正在尝试使用 Javascript 执行器在网站上执行脚本。
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(code);
由于以下错误,这不起作用。
The page at 'https://samplesite.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://localhost:8080/myapi'.
This request has been blocked; the content must be served over HTTPS.
但是,当我删除 headless 选项并作为可见浏览器执行时,同样的方法在控制台中显示警告消息。
有人可以指导我吗?
【问题讨论】:
-
你要执行的脚本是什么?
-
脚本从页面中识别出 href 元素并将其发布到我在本地托管的应用程序中。
标签: google-chrome selenium selenium-webdriver selenium-chromedriver google-chrome-headless