我的问题是我无法找出FluentLenium中的选择器FluentLenium(Selenium)的等效值。
谢谢。
发布于 2015-05-04 15:55:13
在我看来,FluentLenium并没有By.xpath (By.id等)的等价物,因为它完全依赖CssSelector。
因为您可以将自定义筛选器用于:
包含containsWord notContains startsWith notStartsWith endsWith notEndsWith
我个人认为没有理由使用XPath。此外,XPath通常被认为是定位web元素的“不良实践”。
发布于 2017-10-12 20:32:44
是!在FluentLenium 3.4.0中,它们有@FindBy注释,允许您通过xpath找到FluentWebElements。
import org.fluentlenium.adapter.junit.FluentTest;
import org.fluentlenium.core.FluentPage;
import org.fluentlenium.core.annotation.Page;
import org.fluentlenium.core.annotation.PageUrl;
import org.fluentlenium.core.domain.FluentWebElement;
import org.junit.Test;
import org.openqa.selenium.support.FindBy;
@PageUrl("http://www.kennethkuhn.com/")
class Simple extends FluentPage {
@FindBy(xpath = "/html/body/table/tbody[5]/tr/td[1]/center/a[1]/b/font")
FluentWebElement element;
public void enterMuseum(){
element.click();
}
}
public class test extends FluentTest {
@Page
Simple page;
@Test
public void testStuff(){
goTo(page).enterMuseum();
}
}PS:有时候xpath是非常有用的,比如当您正在处理一堆具有类似前端的、永不更改的遗留应用程序时(id/name/class的每个应用程序都不同),但是仍然需要进行测试,因为后端的东西仍然可以破坏修改的内容。尽管如此,如果您正在测试的web应用程序变化很小,尽管很有可能所有的xpath都会中断,所以最好将所有内容锚定到DOM ID中。
https://stackoverflow.com/questions/30031485
复制相似问题