package web;
import java.io.File;
import java.util.concurrent.TimeUnit;
import com.thoughtworks.selenium.*;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
/**
* 启动浏览器小程序
*/
public class TestWebDriver {
WebDriver driver;
Selenium selenium;
@Before
public void setUp(){
//firefox浏览器:
//System.setProperty ( "webdriver.firefox.bin" , "D:/Program Files/Mozilla Firefox/firefox.exe" );
//driver = new FirefoxDriver();
//IE 浏览器:下载IE的驱动包:IEDriverServer.exe
//File file = new File("D:/limengworkspace/test/src/web/IEDriverServer.exe");
//System.setProperty("webdriver.ie.driver",file.getAbsolutePath());
//driver = new InternetExplorerDriver();
//启动chrome_小插曲:注意chromedriver版本问题,之前下载了始终报错,折腾一下午,重新下载个驱动就OK了!
File file = new File("D:/limengworkspace/test/src/web/chromedriver.exe");
System.setProperty ("webdriver.chrome.driver",file.getAbsolutePath());
driver = new ChromeDriver();
//driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
}
@After
public void tearDown(){
driver.quit();
}
@Test
public void test(){
driver.get("http://www.qq.com");
}
}
webdriver启动chorome浏览器
最新推荐文章于 2022-03-27 00:18:56 发布
本文档演示如何在Java中使用WebDriver启动Chrome浏览器。代码示例中,首先设置了ChromeDriver的路径,然后创建并初始化ChromeDriver实例,最后访问了QQ网站。请注意确保WebDriver和ChromeDriver版本兼容。
摘要由CSDN通过智能技术生成