zoukankan      html  css  js  c++  java
  • selenium小例子

    package test.seleniumTest;

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

    import bsh.commands.dir;

    public class AutoTest1 {

        public static void main(String[] args) {
           System.out.println("----------init------------");
    //       System.setProperty("webdriver.ie.driver", "E:/Test/selenium/IEDriverServer.exe");
           System.setProperty("webdriver.chrome.driver", "E:/Test/selenium/chromedriver.exe");
           // 创建一个 ChromeDriver 的接口,用于连接 Chrome,
           //必须要有chromedriver.exe文件,selenium默认不能启动chrome
           // 创建一个 Chrome 的浏览器实例
            WebDriver driver = new ChromeDriver();
            driver.get("http://www.baidu.com");
            
            WebElement element = driver.findElement(By.xpath("//*[@id='kw']"));
    //        WebElement element = driver.findElement(By.name("q"));
            element.sendKeys("hello selenium");
            WebElement element1 = driver.findElement(By.xpath("//*[@id='su']"));
            element1.click();
            
          //等待,超时则抛出错误
            try {
             Thread.sleep(3000);
            } catch (InterruptedException e) {
             e.printStackTrace();
            }
            
          //关闭所有webdriver进程,退出
            driver.quit();
            System.out.println("----------end------------");
        }

    }

  • 相关阅读:
    【t066】致命的珠宝
    【t081】序列长度
    【t081】序列长度(贪心做法)
    【t093】外星密码
    【codeforces 761A】Dasha and Stairs
    【codeforces 761B】Dasha and friends
    【codeforces 761C】Dasha and Password(动态规划做法)
    【codeforces 761C】Dasha and Password(贪心+枚举做法)
    【codeforces 761D】Dasha and Very Difficult Problem
    【u224】传送机
  • 原文地址:https://www.cnblogs.com/dandanfight/p/5915579.html
Copyright © 2011-2022 走看看