注释"@FindBy"的用途是什么? [英] What is the use of Annotation "@FindBy"?

查看:195
本文介绍了注释"@FindBy"的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释WebDriver中的注释@FindBy吗?

Can anyone explain me about Annotation @FindBy in WebDriver?

在哪里以及为什么使用它?

Where and why it is used?

推荐答案

当使用Page Factory支持页面对象时,它可以协助定位器的构建

It's to assist with the construction of locators when using the Page Factory to support your Page Objects

PageFactory Wiki页面

但是,我发现将定位符存储为By对象而不是WebElement更为有用,因为它们更灵活,并且您倾向于避免遇到StaleElementException.

However I'm discovering that I find it more useful to store your locators as By objects rather than WebElements as they are more flexible and you tend to avoid running into the StaleElementException.

By myLocator = By.id("idOfYourElement")

代替

@FindBy(id = "idOfYourElement")
WebElement myLocator;

这样,您可以在断言元素不存在时使用定位器,或者在ExpectedConditions帮助器中使用它.

This way you can also use your locators when asserting the absence of an element or use it in the ExpectedConditions helpers.

这篇关于注释"@FindBy"的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆