注释“@FindBy"有什么用? [英] What is the use of Annotation "@FindBy"?

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

问题描述

谁能解释一下WebDriver 中的注释@FindBy 吗?

Can anyone explain me about Annotation @FindBy in WebDriver?

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

Where and why it is used?

推荐答案

在使用Page Factory支持你的Page Objects时辅助定位器的构建

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

PageFactory 维基页面

但是我发现我发现将定位器存储为 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天全站免登陆