[英]Page Class using PageFactory
I am new to PageFactory
and referring this tutorial https://www.toptal.com/selenium/test-automation-in-selenium-using-page-object-model-and-page-factory 我是
PageFactory
新手,请PageFactory
本教程https://www.toptal.com/selenium/test-automation-in-selenium-using-page-object-model-and-page-factory
An example from this page: 此页面上的示例:
public class HomePage {
private WebDriver driver;
//Page URL
private static String PAGE_URL="https://www.toptal.com";
//Locators
//Apply as Developer Button
@FindBy(how = How.LINK_TEXT, using = "APPLY AS A DEVELOPER")
private WebElement developerApplyButton;
//Constructor
public HomePage(WebDriver driver){
this.driver=driver;
driver.get(PAGE_URL);
//Initialise Elements
PageFactory.initElements(driver, this);
}
public void clickOnDeveloperApplyButton(){
developerApplyButton.click();
}
}
WebDriver
? WebDriver
的私有实例? It is appearing with yellow line for me. how = HOW
and when we can straight away use xpath= //id..
? how = HOW
,何时可以使用xpath= //id..
? WebDriver
parameters? WebDriver
参数? The yellow line is because you are not using the driver variable declared with the class but the one you are passing as the variable to the constructor. 黄线是因为您没有使用在类中声明的驱动程序变量,而是将您作为变量传递给构造函数的变量。 Try using :
尝试使用:
this.driver.get(PAGE_URL); //Initialise Elements PageFactory.initElements(this.driver, this);
You can use xpath = "//div"
straight away when you are not using how.LINK_TEXT as you also have to provide the text for searching the link if you want to locate an element via LINK_TEXT. 不使用how..LINK_TEXT时,可以立即使用
xpath = "//div"
如果要通过LINK_TEXT查找元素,还必须提供用于搜索链接的文本。
In the constructor, you are passing the driver instance so when the page object is created, it has a driver instance as it is not the page instantiating the driver. 在构造函数中,您要传递驱动程序实例,因此在创建页面对象时,它具有驱动程序实例,因为它不是实例化驱动程序的页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.