0

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.

  • Does the current date & time get appended by some javascript code? You mention it's not dynamic, but unless someone is entering it manually, the `xpath.getAttribute("value")` will not contain it. –  Jul 28 '23 at 18:58
  • You can also check [Why input elements "value" attributes are sometimes not presented in the HTML?](https://stackoverflow.com/q/67758297/2453382) –  Jul 28 '23 at 19:02
  • Nope, that was actually a record that was added via import script, & this script was intended to verify that the report data is successfully uploaded. – Arun Kumar Jul 28 '23 at 20:36
  • Update the question with the text based html of the element. – undetected Selenium Jul 28 '23 at 22:29

0 Answers0