Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework: How to make Wait until keyword from selenium library return true or false

I would like to Run a keyword if an element is present on page.

I try using Selenium library's Wait Until Page Contains Element keyword, but it will always return "None", whether or not the element is present. I tried setting custom error, but that won't work either:

${condition} =     Wait Until Page Contains Element    ${locator}    timeout=5   error=false
Run Keyword if  '${condition}'=='false'       click element  ${some_refreshButton_locator}

Keyword click element ${locator} will run only when I make condition '${condition}'=='None'

Am I doing something wrong and how can I make a Selenium Library Wait until... keyword return true or false.

Thanks!

like image 983
emi Avatar asked Sep 14 '25 12:09

emi


1 Answers

Wait Until Page Contains Element does not return anything but will raise error if element is not found. One workaround is to wrap Run Keyword And Ignore Error around it.

*** Settings ***
Library    Selenium2Library

*** Test Cases ***
Test wait
    Open Browser        http://www.google.com/    gc
    ${result}    ${condition}=    Run Keyword And Ignore Error    Wait Until Page Contains    Stackoverflow    timeout=2   error=false
    Run Keyword if  '${condition}'=='false'       Log    clicking
    Close All Browsers
like image 163
Pekka Avatar answered Sep 16 '25 08:09

Pekka