How does @CacheLookup work in WebDriver?

后端 未结 3 1883
情歌与酒
情歌与酒 2021-01-12 21:05

I\'m not sure that I understand the caching principle :

@CacheLookup
@FindBy(how = How.ID, using = namespace + signifLvl)
private WebElement sigLvl;
<         


        
3条回答
  •  鱼传尺愫
    2021-01-12 21:30

    Page Factory works on the principle of configuring the proxies when Page Factory is initialized and every time you use a WebElement it will go and search for the element.

    Now what cachelookup does is it stores elements having @cachelookup annotation applied over it and then stores this element for further reference/s. For example:

      public class SearchPage {
     // 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();
       } }
    

    What this annotation does is it stores the value the searchBox element and now there is no need to search for this element on webpage again.

提交回复
热议问题