How to use selenium 2 PageFactory init Elements with Wait.until()?

后端 未结 3 664
春和景丽
春和景丽 2021-02-01 08:22

The code snippet below works fine, but I\'m having a little trouble with the wait.until() line:

wait.until(new ElementPresent(By.xpath(\"//a[@title=         


        
相关标签:
3条回答
  • 2021-02-01 08:33

    There was a request for implementation on C#.

    Here it is:

    IWebDriver driver = new ChromeDriver();
    RetryingElementLocator retry = new RetryingElementLocator(driver, TimeSpan.FromSeconds(5));
    IPageObjectMemberDecorator decor = new DefaultPageObjectMemberDecorator();
    PageFactory.InitElements(retry.SearchContext, this, decor);
    
    0 讨论(0)
  • 2021-02-01 08:34

    AjaxElementLocatorFactory uses SlowLoadableComponent internally. Check the source code here

    0 讨论(0)
  • 2021-02-01 08:42

    I use PageFactory with AjaxElementLocatorFactory - PageFactory is a support class for the Selenium 2 Page Objects pattern which you are using, and the AjaxElementLocatorFactory is the factory for the element locators. In your case the constructor will looks like:

    public GoogleResultsPage() { 
        PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this);
    }
    

    This code will wait maximum of 15 seconds until the elements specified by annotations will appear on the page, in your case the homePageLink which will be located by xpath. You will not need to use ElementPresent class.

    0 讨论(0)
提交回复
热议问题