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

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

问题描述

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

Can anyone explain me about Annotation @FindBy in WebDriver?

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

Where and why it is used?

推荐答案

当使用页面工厂来支持你的页面对象时,帮助构建定位器

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

PageFactory 维基页面

但是我发现我发现将定位器存储为 By 对象而不是 WebElements 更有用,因为它们更灵活,并且您倾向于避免遇到 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.

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

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