使用selenium的WebDriver和ChromeDriver实现UI自动化

下载chromedriver

chromedriver与chrome的对应关系表:http://blog.csdn.net/huilan_same/article/details/51896672

下载地址:http://chromedriver.storage.googleapis.com/index.html

新建maven类型的JAVA项目,

添加依赖:

                <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.7.1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
		<dependency>
			<groupId>org.jsoup</groupId>
			<artifactId>jsoup</artifactId>
			<version>1.11.1</version>
		</dependency>

  

新建测试类

package com.cctv.web.Selenium;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	System.setProperty("webdriver.chrome.driver", "C:\Users\chromedriver.exe");
    	
    	ChromeOptions options = new ChromeOptions();  
    	options.addArguments("--test-type","--no-check-certificate","--ignore-certificate-errors","--start-maximized","--disable-extensions"); 

    	WebDriver driver = new ChromeDriver(options);
    	driver.get("https://dev.iff-web.cctv.com");
    	driver.findElement(By.id("username")).sendKeys("di");
    	driver.findElement(By.id("password")).sendKeys("di");
    	driver.findElement(By.id("kc-login")).click();
    	
    	//driver.findElementById("username").sendKeys("di");
    	//driver.findElementById("password").sendKeys("di");
    	//driver.findElementById("kc-login").click();
    	try{
    		Document doc=Jsoup.connect("http://dev.iff-web.cctv.com/device-manage?projectID=all&subsystemID=all").get();
    		System.out.println(doc.toString());
    	}catch (IOException e){
    		e.printStackTrace();
    	}
    }
}

 运行java应用时,会打开一个浏览器窗口,但窗口会报错:

网上找的方法试了很多,但是还是一直这样。

原文地址:https://www.cnblogs.com/amoyzhu/p/7832569.html