2

Using Selenium WebDriver,

when annotating your Locators with @FindBy you can choose between a combination of How + using:

@FindBy(how = How.ID, using = "foobar") WebElement foobar;

or you can directly use the location strategy like so:

@FindBy(id = "foobar") WebElement foobar;

I always use the way shorter second version.

I cannot think of any reason why I should use the longer How+using version.

So my question is:

Are there situations where you need to use [How + using]?

If not, why does this longer version even exist?

drkthng
  • 6,651
  • 7
  • 33
  • 53

2 Answers2

1

Greetings and salutations,

If you heard of @FindBy(how=How.CSS , using="locator") you probably want to learn how to manipulate all driver.findElement(By) REST calls. Selenium based on REST calls the assure if a so called WebElement object is exists within the DOM. We can always user @FindBy(id="localtor") which basically say, 'Hey, ima execute a REST call specificly for this HTML tag by id as key and locator as value.

With that said,

working with @FindBy( how=How.CSS, using="locator" ) enable to us a whole different gameplay... Meet @CacheLookup , it will help you use the Browser Cache System to locate everything from the Browser Cache Storage, brings with it lots of performance (about 50% off REST calls runtime )

You can read more here: http://toolsqa.com/selenium-webdriver/cachelookup-in-pageobjectmodel/

Enjoy :)

SysMurff
  • 126
  • 2
  • 14
0

I did a search on documentation available but could not find the reason why How + Using way of annotating with @FindBy is used when we can use the name of location strategy directly.

If you look at the way documentation is written in comments here:

You can either use this annotation by specifying both "how" and "using" or by specifying one of the location strategies (eg: "id") with an appropriate value to use. Both options will delegate down to the matching By methods in By class.

There seems to be no doubt that what How+Using can do, the same can be done using the name of location strategy.

Now, why both are there and can the longer version be better left off, there seems to be no direct mention as of now. You can add a query in Selenium community if you want.

Manu
  • 2,251
  • 19
  • 30