当我想要如下设置Firefox首选项时,我就会遇到这个问题:
public class MyTest{
public WebDriver driver;
public String baseUrl;
@BeforeSuite
public void beforeSuite() {
driver = new FirefoxDriver();
FirefoxOptions options = new FirefoxOptions();
//FirefoxProfile profile = new FirefoxProfile();
options.addPreference("browser.download.folderList", 1);
options.addPreference("browser.download.dir", "C:\\Downloads");
options.addPreference("browser.download.useDownloadDir", true);
options.addPreference("browser.download.viewableInternally.enabledTypes", "");
options.addPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf;text/plain;application/text;text/xml;application/xml");
options.addPreference("pdfjs.disabled", true);
WebDriver driver = FirefoxDriver(options);
//some other code这个问题是针对FirefoxDriver(选项)的。它下划线为The method FirefoxDriver(FirefoxOptions) is undefined for the type MyTest
有人能对此表示支持吗?
发布于 2021-02-02 04:58:31
确保您具有以下导入:
import org.openqa.selenium.firefox.FirefoxOptions;以及使用System.setProperty()行设置GeckoDriver的路径,如下所示:
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");另外,为了使FirefoxOptions生效,您需要删除该行:
driver = new FirefoxDriver();最后更改代码行:
WebDriver driver = FirefoxDriver(options);作为:
driver = FirefoxDriver(options);从历史上看,此错误消息...
FirefoxDriver(FirefoxOptions) is undefined for the type MyTest之前观察到的...was是由于:
在您使用的二进制文件版本之间,旧版本的Selenium.
解决方案
确保:
通过集成开发环境将项目工作区升级到当前版本,并仅使用所需的依赖项重新构建项目。
Test。
tearDown(){}方法中调用driver.quit(),以正常关闭和销毁WebDriver和Web客户端实例。发布于 2021-02-02 05:12:30
你可以试试。
WebDriverManager.firefoxdriver().setup();
发布于 2021-02-02 05:39:14
先删除
driver= new Firefoxdriver()并将最后一行更改为
WebDriver driver = new FirefoxDriver(options);如果你不调用new,你引用的是一个名为FirefoxDriver的函数,
您正在创建FirefoxDriver类的对象,因此应使用new关键字
https://stackoverflow.com/questions/65999979
复制相似问题