driver java options_构造函数FirefoxDriver(FirefoxOptions)未定义

在Java中,可以通过设置FirefoxProfile并使用FirefoxOptions来初始化FirefoxDriver。以下代码展示了如何指定geckodriver路径,加载Firefox配置文件,并打开浏览器访问Google。此外,还设置了页面加载超时和窗口最大化。
摘要由CSDN通过智能技术生成

试试这段代码:

import java.io.File;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxOptions;

import org.openqa.selenium.firefox.FirefoxProfile;

public class FirefoxOptionsDemo {

public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver", "E:\\software and tools\\geckodriver.exe");

FirefoxProfile profile =new FirefoxProfile(new File("C:\\Users\\sys\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ejtrne37.QAProfile"));

FirefoxOptions option=new FirefoxOptions();

option.setProfile(profile);

// Initialize Firefox driver

WebDriver driver = new FirefoxDriver(option);

//Maximize browser window

driver.manage().window().maximize();

//Go to URL which you want to navigate

driver.get("http://www.google.com");

//Set timeout for 5 seconds so that the page may load properly within that time

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

//close firefox browser

driver.close();

}

}

这是供您参考的图片:

4b191ec3-11c7-4e83-af4c-45e72ab3f471.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值