Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium IDE: How to continue script on element not found or on error

I need your help. I just want to continue my Selenium IDE script on Firefox even there's an error or element not found. I'm using script with HTML format.

like image 458
Rommer Dela Cruz Avatar asked Aug 21 '13 05:08

Rommer Dela Cruz


People also ask

How do you handle an element not found in Selenium?

Ideally, the exception occurs due to the use of incorrect element locators in the findElement(By, by) method. To handle this exception, use the wait command. Use Try/Catch to ensure that the program flow is interrupted if the wait command doesn't help.

How do you handle no such element unable to locate an element?

The exception occurs when WebDriver is unable to find and locate elements. Usually, this happens when the tester writes incorrect element locator in the findElement(By, by) method. with the spaces and verify using Try XPath then we can avoid this exception.

What is element not found exception in Selenium?

New Selenium IDE If an element is not found in an HTML DOM using xpath, then the NoSuchElementException is raised. This exception is thrown when the webdriver makes an attempt to locate a web element which is absent from DOM. This is normally encountered if we create an incorrect xpath for an element.

Which function will not throw an exception if targeted element is not found on the page?

Expected Behavior -FindElements() functions should return an empty collection/null/NoSuchElementException if the element is not found found on a page.


3 Answers

You have to make an explicit check if an element is present before using this element in the next command (which might cause an error and break an execution of a script). User extension "sideflow" enables conditional jumps inside your code.

Here is home page of sideflow extension: https://github.com/darrenderidder/sideflow

With sideflow extension you may use code like this:

storeElementPresent id=btnRecSearch isPresent
gotoIf  ${isPresent} == false   End
click   id=btnRecSearch 
....
label   End
like image 163
Yevgen Ulyanenkov Avatar answered Sep 20 '22 17:09

Yevgen Ulyanenkov


This example is for the new Selenium IDE version 3 that works on Firefox and Chrome. The basic premise:

1) store xpath count -- this saves the count of elements that match to a variable

store xpath count | xpath=//body[@id='error-page'] | error

2) if -- in this case test the count is more than 0

if | ${error} > 0

3) do some magic stuff

4) end

end

Selenium IDE 3 - if element exists example

Here is an article I posted using the same example: http://lance.bio/2018/12/21/selenium-ide-if-element-exists/

like image 20
Lance Cleveland Avatar answered Sep 20 '22 17:09

Lance Cleveland


If you use all verify related command then your script do not stop if element is not found by seleniun IDE but if you use assert related command then your script is stop if that element is not found by selenium ide

If have to create your script using verifytext command then run that script and see your script will not stop if element is not displayed

like image 45
Ankit jain Avatar answered Sep 19 '22 17:09

Ankit jain