完整代码实现如下:

package linear;

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

/*
 * 李盈辉
 *2016-12-2
 * */
public class loginCase {
        // TODO Auto-generated constructor stub
    public static void main(String[] args) throws Exception{
            WebDriver driver;
            System.setProperty("webdriver.chrome.marionette","C:\\Program Files (x86)\\Google\\Chrome\\Application\\geckodriver.exe");
            driver = new ChromeDriver();
            driver.manage().window().maximize();
            System.out.println("浏览器已经启动");
            //在网站注册账号,并替换成自己的账号和密码,即可实现登录
            driver.get("https://www.tangcredit.com/");
            driver.findElement(By.xpath("//div[@id='register518']/span[2]")).click();
            Thread.sleep(5000);
            driver.findElement(By.id("model_phone")).clear();
            driver.findElement(By.id("model_phone")).sendKeys("tell-phone");
            driver.findElement(By.id("model_password")).clear();
            driver.findElement(By.id("model_password")).sendKeys("password");
            driver.findElement(By.cssSelector("input.btn.btn-danger")).click();
            System.out.println("用户已经登录");
        }

}

posted on 2016-12-02 17:36  漫步馥路道  阅读(548)  评论(0编辑  收藏  举报