• 使用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应用时,会打开一个浏览器窗口,但窗口会报错:

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

  • 相关阅读:
    测试用例
    HDU 5024 Wang Xifeng's Little Plot(枚举)
    HDU 1165 Eddy's research II
    java大数总结
    UVA 1646 Edge Case
    HDU 2553 N皇后问题
    【24题】试题库问题【网络流】
    YAPTCHA【数论】
    YAPTCHA【数论】
    YAPTCHA【数论】
  • 原文地址:https://www.cnblogs.com/amoyzhu/p/7832569.html
Copyright © 2020-2023  润新知