在basepage.java中对selenium常用方法进行封装,后续页面元素封装都继承该类。

重点见红框,构造函数需要传入一个driver,这是为了保证写脚本时所使用的是同一个driver

3、对selenium常用方法进行二次封装


代码如下:

package framework;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class basepage {

WebDriver driver;

public basepage(WebDriver driver){
this.driver = driver;
}

public WebElement find_id(String id){
return driver.findElement(By.id(id));
}

public WebElement find_xpath(String xpath){
return driver.findElement(By.xpath(xpath));
}

public WebElement find_link_text(String linkText){
return driver.findElement(By.linkText(linkText));
}

public void click(WebElement element){
element.click();
}

public void send_keys(WebElement element,String str){
element.clear();
element.sendKeys(str);
}

public void sleep(int SECONDS){
try {
Thread.sleep(SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-08
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-11-12
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案