Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework - check if element defined by xpath exists

I'm wondering, I'd love to find or write condition to check if some element exists. If it does than I want to execute body of IF condition. If it doesn't exist than to execute body of ELSE.

Is there some condition like this or is it necessary to write by myself somehow?

like image 607
Petr Bečka Avatar asked Dec 06 '22 16:12

Petr Bečka


1 Answers

By locating the element using xpath, I assume that you're using Sselenium2Library. In that lib there is a keyword named:

Page Should Contain Element which requires an argument, which is a selector, for example the xpath that defines your element.

The keyword failes, if the page does not contain the specified element.

For the condition, use this:

${Result}= Page Should Contain Element ${Xpath} Run Keyword Unless '${RESULT}'=='PASS' Keyword args*

You can also use an other keyword: Xpath Should Match X Times

like image 114
Richard Zilahi Avatar answered Dec 24 '22 09:12

Richard Zilahi