My problem is that I can't figure out the equivalent of the selector XPath(selenium) in FluentLenium.
Thank you.
My problem is that I can't figure out the equivalent of the selector XPath(selenium) in FluentLenium.
Thank you.
It seems to me that FluentLenium doesn`t have By.xpath (By.id, etc) equivalent as it relies solely on CssSelector.
Since you can use Custom filter with:
contains containsWord notContains startsWith notStartsWith endsWith notEndsWith
I personally don't see any reason to use XPath. Moreover, XPath often considered as a "bad practice" to locate web element.
YES! In FluentLenium 3.4.0 they have @FindBy annotations that will allow you to find FluentWebElements by xpath.
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: There are sometimes where xpath is extremely useful, such as when you're working on a bunch of legacy applications with similar front-ends that never change (id/name/class's all different per app) but still needs to be tested because back-end stuff can still break things on revisions. Although, if the web app you're testing changes even slightly though there's a good chance all your xpaths will break and it's definitely better to anchor everything to DOM ID's.