环境搭建
语言环境:Java8
IDE:IDEA
首先,在maven中引入selenium-java。
<dependencies>
<!--必须引入 -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
</dependencies>
之后在项目路径下,放入下载好的chrome driver,如果是最新版的chrome,请使用最新版的驱动,不然会报错。
chrome 74.x版本可用的驱动如下:
链接:https://pan.baidu.com/s/1VdnoKM7RYqnmm1Ud-bJucg
提取码:hmjh
开始测试
public static void main(String[] args) {
WebDriver driver;
String url="https://www.baidu.com";
System.setProperty("webdriver.chrome.driver","chromedriver_74.exe");
driver =new ChromeDriver();
driver.get(url);
driver.findElement(By.name("wd")).sendKeys("111");
System.out.println(driver.getTitle());
}
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 38578
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
五月 15, 2019 8:57:05 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS
百度一下,你就知道