Partial text gets retrieved from getTextFromXpath function where we are passing a xpath to the function

35 Views Asked by At

I have created a function as written below, under the action utility under the framework:

public String getTextByXpath(WebElement xpath) throws Exception {
        waitForXPath("wait for element", xpath);
        Assert.assertNotNull(xpath);
        LOG().info("Element to get text is Present");
        String value = xpath.getAttribute("value");
        LOG().info("Actual Text:" + value);
        return value;
    }

Where I'm passing a web element's(input field) path to get the text.

For e.g

@FindBy(xpath = "//input[@id='gwt-uid-5643']") 
WebElement input_UserName;

this is an input field where the value contains some text concatenated with the current date & time but it's not dynamic.

Given that the element is present & visible, using this function gets me a partial value from i.e. only the text part from the input field, not the date/time which was appended to the text.

I have tried different methods but still had no success.

0

There are 0 best solutions below