AMK
AMK

Reputation: 91

Value attribute of a text box retains old value even after new value has been keyed in

This is the HTML I have for a text box on a form:

<input type="text" onblur="javascript:itemLostFocus('18A3461989AC0244E050A20AB17C4671');" onkeydown="javascript:itemChanging('18A3461989AC0244E050A20AB17C4671');" value="972" name="18A3461989AC0244E050A20AB17C4671" maxlength="3" size="3"/>

What I do next is update the text box input to 123 from 972. Now if I check the value attribute of the same text box using the getAttribute("value") method of Selenium WebDriver, it still shows 972 and not 123.

What attribute should I look for to retrieve the value 123?

Upvotes: 0

Views: 780

Answers (1)

greatgumz
greatgumz

Reputation: 418

Because Selenium WebDriver executes so quickly, when you are updating the input value, your getAttribute("value") method is executing before your input gets a chance to update.

In your BasePage you need a waitFor boolean

protected void waitFor(BooleanCondition condition) {
    waitFor(condition, "(none)");
}

And in your Object page you need to call the waitFor method after you update your input and before you call getAttribute("value")

public ObjectPage readValue(String value) {
    // whatever update happens
    waitFor(Conditions.elementIsNotDisplayed("#waiting_dialog"));
    return this;
}

Upvotes: 2

Related Questions