简体   繁体   中英

Selenium @FindBy - when would you use How?

I've been reading the Selenium API docs for FindBy to try and understand the difference between the two lines of code below.

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

I've tried using both in my own page object and they seem to be functionally identical. I've tried using id, css selector and xpath to see if there was a difference but so far I can't see any benefit in using the second, more verbose line of code.

Would appreciate it if someone could help me understand when/why I'd use that over the first line.

I'm new to coding so I may be missing something elementary but I HAVE tried to find the answer myself before posting here :)

Both are the same, the "How" can be used in other cases than finding elements. In general you can say:

"I bought a porshe" and everybody understands, you bought a car brand porsche. or "I bought a car, brand porshe" and everybody understands, you bought a car brand porsche.

If Porshe would manufacture planes and ships, than would be neccessary the second expresion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM