回答
我可以引用API-documentation吗?
用于标记上的页面对象的字段来指示替代机制用于定位元件或元素的列表。与
PageFactory#proxyElement
结合使用可以让用户快速轻松地创建PageObjects。
所以,如果你使用PageObject
模式则增加了此批注类成员和WebDriver
对象初始化过程中自动注入适当WebElement
s到它(当叫PageFactory.initElements()
)。
我强烈建议使用此链接并阅读有关PageObject
pattern and @FindBy
annotations usage的更多示例。
它来帮助定位器的建设使用页面出厂设置时,支持你的页面对象
但是我发现,我觉得它更有助于你的定位器存储为由对象,而而不是WebElements,因为它们更加灵活,并且您倾向于避免遇到StaleElementException。
By myLocator = By.id("idOfYourElement")
代替
@FindBy(id = "idOfYourElement")
WebElement myLocator;
这样断言缺少的元素时,你也可以用你的定位器或ExpectedConditions助手使用它。
我很难理解为什么有人会使用@FindBy而不是By对象。 – stuart 2015-10-02 03:01:11
@elroso在删除注释时,我可以使用PageFactory.initElements(驱动程序,页面)方法吗?谢谢 – 2016-02-08 22:20:44
使用By而不是@FindBy的好解释。谢谢 :) – 2016-04-15 15:28:09
您还可以使用Pagefactory,并有类似:现在
@FindBy(how = How.NAME, using = "logonName")
private WebElement logonNameField;
@FindBy(how = How.NAME, using = "password")
private WebElement passwordField;
,至于怎么,你可以有:
- CLASS_NAME
- CSS
- ID
- ID_OR_NAME
- LINK_TEXT
- NAME
- PARTIAL_LINK_TEXT
- TAG_NAME
- XPATH
- 类
或者您可以使用自己的DOM搜索加了XPath,这将是webdriver的API之外,但它应该工作。
- 1. 在Hibernate Annotation下使用命名查询有什么好处
- 2. SAL(Source Annotation Language)的用途是什么?SAL 1和2有什么不同?
- 3. Android,neenbedankt A.P和Support Annotation有什么区别?
- 4. 在Selenium中使用@FindBy而没有PageFactory
- 5. Spring AOP by annotation pointcut annotation not retrieve
- 6. 使用@FindBy查找WebElementS
- 7. Grails .findBy不适用于redis
- 8. 未知的findBy
- 9. isElementpresent法FindBy
- 10. Symfony2的findBy + indexBy
- 11. Java 1.5 Enum:为什么我不能在1.5枚枚举中使用'findBy'?
- 12. 使用Hibernare Bytecode Enhancement Without Annotation
- 13. 在Spring AOP中使用@annotation
- 14. Spring 2 Hibernate Annotation
- 15. Autowire without annotation @Autowired
- 16. @Proxy in Hibernate Annotation
- 17. Guice @Nullable annotation
- 18. Skobbler&Annotation动画
- 19. Auto Scaling Image Annotation
- 20. Doctrine findby遍历所有行以显示所有用户
- 21. [,]有什么用?
- 22. Spring JPA findBy口音
- 23. findBy关系领域
- 24. Zend Framework findBy魔法?
- 25. Spring Validation using Annotation @RegExp
- 26. Hibernate Annotation Placement问题
- 27. 为什么在我的生产环境中出现 - > findBy()错误?
- 28. 为什么doctrine2 ODM的findBy()和createQueryBuilder() - > getQuery() - > execute()的结果各不相同?
- 29. chomp有什么用?
- 30. getchar()有什么用?
感谢您的回复。所以,我有另一个问题......它会被用于元素动态地改变他们的定位器? – mra419 2012-01-27 15:42:49
@ user1163375你说“动态地改变它们的定位器”是什么意思? – 2012-01-30 03:55:16
我的理解是“@FindBy”当元素ID在Web应用程序中动态更改时使用注释....如果错误,请纠正错误。 – mra419 2012-01-30 06:44:05