自动化测试-登录

    
        org.seleniumhq.selenium
        selenium-java
        3.141.59
 

 

 

package com.winner;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
 
public class Open {
    
    public static void main(String args[]) throws InterruptedException {
        
        //指定火狐驱动的地址
        System.setProperty("webdriver.gecko.driver","E:\\toos\\geckodriver.exe");
        
        //实例化一个WebDriver的对象,此时会启动火狐浏览器
        WebDriver driver = new FirefoxDriver();
        for(int i=0;i<3;i++){
            driver.get("https://www.baidu.com");
            //输入用户名
            driver.findElement(By.id("txtuser")).sendKeys("");
            //输入密码
            driver.findElement(By.id("txtpwd")).sendKeys("");
            driver.findElement(By.id("dl")).click();
            
            //强制等待3秒
            //Thread.sleep(3000);
            
            JavascriptExecutor js = (JavascriptExecutor) driver;

            js.executeScript("logout()");
        }
    
        
        //关闭火狐浏览器
        driver.quit();
        
    }
 
}

你可能感兴趣的:(自动化测试-登录)