Tuesday, March 17, 2009

"is_element_present" does not return FALSE !!!

While writing automation script in selenium using ruby I had a need to assert and check element on the page. I have created an API for element present and check assertion to mention in the report and log. So I got “is_element_present” method which returns TRUE if it finds element on the page otherwise FALSE.

But actually it doesn’t return FALSE. In fact throws an error and just demolish all the script and go out from code. You can handle this situation and even can write this to your report and log as well.

Have a look:

def is_element_present(id)
begin
$browser.is_element_present(id)
rescue SeleniumCommandError
return FALSE
end
end


this actually handling the exception and that case when element doesn’t present on the page you can explicitly return FALSE. By this, “is_element_present” works expectedly.