Need to wait on value not being empty...

534 views
Skip to first unread message

Karl Krasnowsky

unread,
Jul 9, 2023, 8:44:32 PM7/9/23
to Selenium Users
We have a test requirements that requires that after a page loads, we replace the default values of a text field elements with another string.
Seems easy, but the problem is, this react app is dynamically rendering the text in the fields after the page loads... so while the implicit wait will wait until the actual element is found, the text is not updated yet so the routine will attempt to clear the value that is not there yet and enter the new string... after which we have a condition where the two values are concatenated.
What I believe I need is a wait for when the "value" attribute of an element is not empty (I've seen many examples of waiting until a text field has a specific value, but this can't work in this case, simply that it has a value), but I'm having a heck of a time finding an example of this. Thought it would be relatively easy to find...

This is in java.

Gouri Sankar

unread,
Jul 9, 2023, 9:34:35 PM7/9/23
to seleniu...@googlegroups.com
Hi,

It would be great if you provide more details and url if possible to provide best solutions 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5ea4b0c0-ad0f-4950-96aa-9443e43cca0fn%40googlegroups.com.
--
Sent From iphone

Abhishek Kumar

unread,
Jul 10, 2023, 10:53:01 AM7/10/23
to Selenium Users
Similar situation I have also faced in my project, 
What I have done, I have just created a magic Utility function for send keys. 

public void magicClick(By by, int count) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(Constants.DEFAULT_TIME_OUT));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
int loop = 0;
while (loop < count) {
wait.until(ExpectedConditions.elementToBeClickable(by)).click();
loop++;
}
}

and call this method 5 to 6 times where you are entering the data,  magicClick(firstname, 7)

Hope this make shifter will work for you as well.
Message has been deleted

Karl Krasnowsky

unread,
Jul 10, 2023, 11:49:16 AM7/10/23
to Selenium Users
@Sankar

Provide an url to what exactly? my not yet released web site?
I believe I was as clear as I could be... I need to wait on a text input element to be updated with text data injected by a javascript process before continuing. when the element first renders it's visible, but without initial text. The joy of a dynamic web site.

Karl Krasnowsky

unread,
Jul 10, 2023, 11:53:12 AM7/10/23
to Selenium Users
@khatr...@gmail.com

>> wait.until(ExpectedConditions.visibilityOfElementLocated(by));

Thanks, but my problem isn't that the element isn't visible, it is... the problem is the value attribute of the element is not applied yet.

joseph...@gmail.com

unread,
Jul 17, 2023, 1:40:59 PM7/17/23
to Selenium Users

If the field always ends up with a known default value when React is done, you could probably do something like

wait.until(ExpectedConditions.attributeToBe(ByLocator/WebElement, "value", "default text that shows up"));

Another option could be

wait.until(ExpectedConditions.attributeToBeNotEmpty(WebElement, "value")); , but I've not used this one personally so I don't know if it will work on the value attribute of an input.

Another possibility to consider could be using ExpectedConditions.not() with ExpectedConditions.attributeToBe(), which is likely similar to what ExpectedConditions.attributeToBeNotEmpty is doing. That would look something like this.

wait.until(ExpectedConditions.not(ExpectedConditions.attributeToBe(ByLocator/WebElement, "value", ""))); , but the handling of empty string, "", can sometimes lead to unexpected results so be careful.

Good luck!
Reply all
Reply to author
Forward
0 new messages