首页 > 代码库 > selenium2-java 浏览器下进行登录
selenium2-java 浏览器下进行登录
完整代码实现如下:
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("用户已经登录");
}
}
selenium2-java 浏览器下进行登录