selenium 自动化测试

来源:互联网 发布:it编程培训中心 编辑:程序博客网 时间:2024/06/14 21:31

selenium github

public class test1 {     public static void main(String[] args) throws Exception{        // 谷歌浏览器驱动        System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");        // 谷歌浏览器软件地址        ChromeOptions options = new ChromeOptions();        options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");        WebDriver driver = new ChromeDriver(options);        // 驱动的网址        driver.get("http://www.baidu.com/");        // 浏览器窗口变大        driver.manage().window().maximize();        // 定位输入框元素        WebElement txtbox = driver.findElement(By.name("wd"));        // 在输入框输入文本        txtbox.sendKeys("HelloWorld");        // 定位按钮元素        WebElement btn = driver.findElement(By.id("su"));        // 点击按钮        btn.click();        // 关闭浏览器        //driver.quit();    }}