【问题标题】:Difference between @FindBy vs driver.findElement()?@FindBy 与 driver.findElement() 之间的区别?
【发布时间】:2018-03-15 06:32:05
【问题描述】:

我都用过,但不知道应该在哪里使用@findBy,在哪里使用driver.findElement()

我听说@FindBy 的行为是动态的,而driver.findElement() 的行为是静态的。这是什么意思?

【问题讨论】:

标签: selenium selenium-webdriver webdriver findby page-factory


【解决方案1】:

@FindBydriver.findElement() 是实现相同目标的不同方法,即通过不同的Locator Strategies 定位元素。

当使用 PageFactory 时,我们可以使用Annotation Type FindByFindBy 注释可以帮助我们去除 boiler-plate 代码,我们在查找元素时通常以 findElement()findElements() 的形式使用。

举个例子:

WebElement element = driver.findElement(By.name("q"));
element.click();

变成:

element.click();

你可以在How to use explicit waits with PageFactory fields and the PageObject patternHow to use explicit waits with PageFactory fields and the PageObject pattern@@Simon Stewart 的讨论中找到关于同一主题的 cmets

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 2014-10-30
    • 2021-12-07
    相关资源
    最近更新 更多