Waiting for a web element to appear on the web page

If you need to get the value of a web element on a web page, but it takes some time for the element to appear on the page, you can use a custom action to avoid setting an explicit wait for the Web Element action or using Wait action in the workflow.

@CustomScriptAction(
)

def customScript() {

setFluentWaitTimeout(20000)
setFluentWaitPollingInterval(300)
fluentWait()
 .ignoring(org.openqa.selenium.NoSuchElementException.class)
 .until(ExpectedConditions.presenceOfElementLocated(byCssSelector('css-selector')))

}

Here is a sample script that uses the action.
The bot:

  • opens an online translator
  • inserts a large text in English and translates it into Finnish
  • waits for translation to be finished and for the translated text to appear on the page
  • once the text is there, saves it to a variable.

wait-for-element.zip (1.6 KB)

3 Likes