5--Selenium环境准备--firefox与geckodriver

时间:2023-03-08 23:57:30
5--Selenium环境准备--firefox与geckodriver

selenium2时打开firefox浏览器是不需要安装firefoxdriver的,但是selenium3不支持向前支持火狐浏览器了,40以后版本的火狐,运行会出现问题。

1、下载geckodriver

https://github.com/mozilla/geckodriver/releases

chrome浏览器需要下载chromedriver

然后在代码中添加即可

public class lesson4 {

    @Test
public void BrowserTest() throws InterruptedException{ /*----------------------------lesson1--------------------打开浏览器*/
//chrome浏览器需要添加chromedriver,ie需要增加internateExplorerdriver
//而selenium2中firefox无需,selenium3中需要添加geckodriver
System.setProperty("webdriver.gecko.driver", "G:/Testing/selenium/geckodriver.exe");
//打开浏览器
WebDriver dr=new FirefoxDriver();
Thread.sleep(2000); /*----------------------------lesson2--------------------------*/
//浏览器最大化
dr.manage().window().maximize();
//打开百度
dr.get("https://www.baidu.com/");
//获取打开页面的title,并判断title是否正确
System.out.println("the title is:"+dr.getTitle());
System.out.println("Current url is:"+dr.getCurrentUrl());
//判断页面跳转的方式:打开一个url,等待3s,在获取currenturl,判断,不相等则发生跳转成功
//判断页面跳转的方式:通过页面的title判断 /*----------------------------lesson3--------------------------*/
//自定义profile //关闭浏览器:close--只是关闭浏览器,但是服务不停,quit服务也会停掉,推荐quit
dr.quit();
}

参考资料:https://blog.****.net/jinhe123/article/details/69946234