我需要使用 WebDriver 打开 Firefox 中的“首选项”页面,以便以特定于浏览器的方式清除缓存。
在调查该问题时,我发现 a Python solution并尝试将其翻译为 Java,但 WebDriver 误解了 uri:
driver.get("about:preferences#privacy");
并发送“/about:preferences#privacy”,而 Firefox 不知道如何打开。
我还尝试了 JavaScript 方式:
driver.executeScript("window.location.replace('about:preferences#privacy');")
driver.executeScript("window.open('about:preferences#privacy');")
但浏览器会忽略这些。
我认为必须有一种 Java 方式,因为这已经使用 Python WebDriver 实现了(请参阅第一个链接)。
更新:事实证明这是一个非 WebDriver 问题。事实上,这源于我们正在使用的测试框架,该框架是围绕 Selenium 构建的 - Quantum Perfecto 。所描述的行为不会发生在纯 Selenium 中。 我向框架支持团队发送了请求,要求解决他们代码中的问题。
最佳答案
Custom Firefox Profile for Selenium简介
您将像这样使用它:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("<your-profile-name>");
WebDriver driver = new FirefoxDriver(myprofile);
如Mike 'Pomax' Kamermans说,最好是根据您的要求创建配置文件。
如果您需要以编程方式创建环境,请使用配置管理(如 Puppet/Chef/Ansible),甚至使用 maven生成多个可与自定义脚本一起使用的 environment.properties
来配置(或从头开始创建)Firefox 配置文件,这在 this thread 中得到了解答
关于java - 如何使用 java WebDriver 在 Firefox 中打开 "about:preferences",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57421406/