设计思想:面向对象,将单个页面所有可能用到元素封装到一个page类中,并提供一些常用的方法,其属性就代表页面元素,普通方法代表对元素所做的操作

以博客园的登录页面为例:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class BlogLogin {

//登陆账号元素
WebElement account;

//登陆密码元素
WebElement password

//登录按钮元素
WebElement loginBtn;

//构造方法,用于初始化页面对象及其页面元素
public BlogLogin(WebDriver driver) {

//定位账号输入框
account=driver.findElement(By.id("input1"));

//定位到密码输入框
password=driver.findElement(By.id("input2"));

//定位到登录按钮
loginBtn=driver.findElement(By.id("signin"));
}

//提供一个登录的方法,只需要提供用户名,密码即可登录
public void Login(String username,String userpassword){
account.sendKeys(username);
password.sendKeys(userpassword);
loginBtn.click();
}
}

相关文章:

  • 2022-01-18
  • 2021-09-15
  • 2022-12-23
  • 2018-04-28
  • 2021-12-07
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2020-10-13
  • 2022-12-23
  • 2021-11-09
  • 2021-12-18
相关资源
相似解决方案