package brand;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.firefox.FirefoxDriver;
public class BrandLogin {
private WebDriver driver;
private Navigation navigation;
private String baseUrl = "完整URL地址,需加http";
@Test
public void brandLogin() {
//設置firefox瀏覽器的位置
System.setProperty("webdriver.firefox.bin",
"D:/programs/Mozilla Firefox/firefox.exe");
//創建WebDriver對象
driver = new FirefoxDriver();
navigation = driver.navigate();
//加載到指定url
navigation.to(baseUrl);
//獲取輸入框的id,並在輸入框中輸入用戶名
WebElement loginInput = driver.findElement(By.id("uname"));
loginInput.sendKeys("輸入網站的用戶名");
//獲取輸入框的id,並在輸入框中輸入密碼
WebElement pwdInput = driver.findElement(By.id("upwd"));
pwdInput.sendKeys("輸入網站的密碼");
//獲取登陸按鈕的className,並點擊
WebElement loginBtn = driver.findElement(By.className("LBtn"));
loginBtn.click();
}
}
selenium自動化測試實現對網站的登陸(使用java編寫)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.