首页 > 技术文章 > Java+selenium自动化测试基础

haoabcd2010 2018-03-28 14:57 原文

Java+selenium maven配置

maven的配置,但还需要建立maven的本地库,修改apach-maven的setting.xml

http://www.cnblogs.com/haoabcd2010/p/8664387.html

 

Java+selenium自动化测试基础脚本

java配置好,maven配置好后,下载好selenium,浏览器驱动装好,试着建立一个maven项目,可以运行就可以进行自动化测试了

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import com.google.common.io.Files;
  
public class FindName {  
    
    public static void wait(int time) {
        try {
            Thread.sleep(time*1000);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
  
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");  
        //初始化一个谷歌浏览器实例,实例名称叫driver  
        WebDriver driver = new ChromeDriver();  
        //最大化窗口
        driver.manage().window().maximize();  
        // get()打开一个站点  
        driver.get("https://www.baidu.com/");
        wait(3);
        driver.findElement(By.id("kw")).sendKeys("xxxx");
        
        driver.findElement(By.id("su")).click();
        
        //关闭并退出浏览器  
        //driver.quit();  
    }  
}  
View Code

 

webdriver定位

这篇博客写得很好,看了很有收获,总结得很好

http://www.cnblogs.com/TankXiao/p/5222238.html

后来遇到一个坑点,就是报错,无法定位xpath,后来发现是iframe的缘故

https://www.cnblogs.com/ycyzharry/p/7218429.html

 

推荐阅读