Trying to verify if an element contains a specific text, but the keyword Element Should Contain does not find the text even if I explicitly put in the xpath attribute that it contains the text. However the keyword Wait Until Page Contains Element works.
Ran the script below and got the following results
#this was successful
Wait until Page Contains Element xpath://div[@id="header"]//span[contains(text(), "text")]
#this resulted to: should have contained text 'text' but its text was ''
Element Should Contain xpath://div[@id="header"]//span[contains(text(), "text")] text
There is a difference between the Element Should Contain and Wait until Page Contains Element.
The first will only check if at the moment the DOM contains the element with a substring of that text, while the last one will wait (by default) up to 5 seconds for that element to appear in DOM in order to validate if it exists. Or, to rephrase: the first one checks if the condition is correct, the other one listens for changes in the DOM to detect the needed value. Maybe your text is shown after some loading time?
From the documentation:
Element Should Contain:
Verifies that element locator contains text expected. ... Use Element Text Should Be if you want to match the exact text, not a substring.
Wait Until Page Contains Element:
Waits until element locator appears on current page. Fails if timeout expires before the element appears.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With