What is the equivalent ExpectedCondition of "Wait Until Page Contains" of robot framework in Java What is the equivalent ExpectedCondition of "Wait Until Page Contains" of robot framework in Java selenium selenium

What is the equivalent ExpectedCondition of "Wait Until Page Contains" of robot framework in Java


There is no direct analog, that's a capability developed explicitly in in Robot Framework.
In the same time, you can achieve it with ExpectedCondition's presenceOfElementLocated() with explicit/fluent wait (the latter is just more customizable version of the first, btw).

For a locator, use this xpath:

//*[contains(., "Your Text Here")]

This is what Robotf Framework actually does, quite clever I must admit.


Wait Until Page Contains

Wait Until Page Contains is the implementation to wait for the text to appear within the HTML DOM. It is documented as:

Keyword                     Arguments                           Documentation-------                     ---------                           -------------Wait Until Page Contains    text, timeout=None, error=None      Waits until text appears on current page.                                                                Fails if timeout expires before the text appears. See the Timeouts section for more information about using timeouts and their default value.                                                                error can be used to override the default error message.

Source Code:

@keyworddef wait_until_page_contains(self, text, timeout=None, error=None):    """Waits until ``text`` appears on current page.    Fails if ``timeout`` expires before the text appears. See    the `Timeouts` section for more information about using timeouts    and their default value.    ``error`` can be used to override the default error message.    """    self._wait_until(lambda: self.is_text_present(text),                     "Text '%s' did not appear in <TIMEOUT>." % text,                     timeout, error)

So the equivalent ExpectedConditions can be either of the following:

Note: One significant difference is, while wait_until_page_contains is relative to the current page i.e. the current DOM Tree, the ExpectedConditions are based on WebElements on the current page which makes your Tests much more granular.


There is like more functions like but this three use mostly..

Wait Until Element Is Enabled assumes that the element exists on the page, and will wait until the element is enabled (not readonly, and not disabled). If the element does not exist, it will fail immediately (or after a timeout if you have an implicit wait)

Wait Until Element is Visible assumes that the element exists on the page, and will wait until the element is visible. If the element does not exist, it will fail immediately (or after a timeout if you have an implicit wait)

Wait Until Page Contains Element makes no assumptions about the element. It waits until the element is actually on the page, regardless if it is visible, invisible, enabled, or disabled. It does not require an implicit wait, since this keyword is an explicit wait.

The most complete solution is to wait for it to be on the page, wait for it to be visible, and then wait for it to be enabled.

If the element will always be on the page, you can skip the first check (ie: if there's no javascript that can create or delete the element).

If the element will always be enabled, you don't need to wait for it to become enabled (ie: if there's no javascript to disable or enable the element)

For simple static pages, you really only need to check that an element is visible. Even that isn't usually necessary since selenium doesn't return from opening a page until the page is loaded. The problem comes when the page is dynamic. That is, when there is javascript that can change what is on the page and whether it is visible or enabled, after the html has loaded.

No, because "is loaded" can mean different things in different applications. The browser will set the variable document.readyState to "complete" when it's done loading the html. You can check for that in robot with something like Wait for condition return window.document.readyState === 'complete'. Again, if you have javascript that runs on the page, this may not be sufficient since the page might change after the initial HTML is loaded.