Identifying the Web elements using XPATH and CSS in LeanFT

We can use XPATH and CSS selectors to identify the web elements. Below example illustrates how to use XPATH and CSS in LeanFT.

In below example, we have identified edit box using XPATH and CSS.

For more advanced XPATH expressions, you can visit – https://selenium-interview-questions.blogspot.in/2014/02/how-to-identify-elements-using-xpath-in.html

For more advanced CSS expressions, you can visit – https://selenium-interview-questions.blogspot.in/2014/02/how-to-identify-elements-using.html

package leanft;

import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.web.*;
import org.junit.Test;

public class CssXpathTest extends BaseTest {

    @Test
    public void test() throws Exception{

        Browser browser = BrowserFactory.launch(BrowserType.CHROME);
        try{
            //Navigate to https://www.softpost.org/selenium-test-page/
            browser.navigate("https://www.softpost.org/selenium-test-page/");
            browser.sync();

            //set value in edit box using xpath
            browser.describe(EditField.class,new EditFieldDescription.Builder()
            .xpath("//input[@id='fn']").build()).setValue("Sagar");

            //set value in edit box using css
            browser.describe(EditField.class,new EditFieldDescription.Builder()
                    .cssSelector("input[id='fn']").build()).setValue("Salunke");


        }
        catch(AssertionError ex){
           //Report the Exception
           Reporter.reportEvent("Exception","Test failed", Status.Failed, ex);
           throw ex;
        }
        finally{
            //Close the browser
            browser.close();
        }
    }
}

You may also like...