Pagefactory 使用

上一篇 / 下一篇  2012-04-20 09:01:02 / 个人分类:selenium2

http://code.google.com/p/selenium/wiki/PageFactory ############################initialize############################################ import org.openqa.selenium.support.PageFactory; GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class); #############################pagefactory example 1################################ import org.openqa.selenium.WebElement; public class GoogleSearchPage { // Here's the element private WebElement q; public void searchFor(String text) { // And here we use it. Note that it looks like we've // not properly instantiated it yet.... q.sendKeys(text); q.submit(); } } ###########################pagefactory example 2################################## import org.openqa.selenium.By; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.openqa.selenium.WebElement; public class GoogleSearchPage { // The element is now looked up using the name attribute, // and we never look it up once it has been used the first time @FindBy(how = How.NAME, using = "q") @CacheLookup private WebElement searchBox; public void searchFor(String text) { // We continue using the element just as before searchBox.sendKeys(text); searchBox.submit(); } } ###########################Annotations example 1################################## public class GoogleSearchPage { @FindBy(name = "q") private WebElement searchBox; // The rest of the class is unchanged. } ###########################Annotations example 2################################## @FindBys({@FindBy(id = "tmRegister"), @FindBy(tagName = "a")})


TAG:

 

评分:0

我来说两句

Open Toolbar