1

My problem is that I can't figure out the equivalent of the selector XPath(selenium) in FluentLenium.

Thank you.

AmineP90X
  • 33
  • 5

2 Answers2

1

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.

  • The reason why I tried to use XPath is that my application is too huge and not all the widgets (GWT) have the ID's. But now, I'm seeing that findById is the most effective and reliable locator. Thank you Ivan. – AmineP90X May 05 '15 at 09:34
1

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.

code_disciple1
  • 121
  • 1
  • 11