Selenium IDE: how to continue a script by an element not found or by mistake

I need your help. I just want to continue using the Selenium IDE script in Firefox, even there is no error or element not found. I am using a script with HTML format.

+4
source share
8 answers

You need to do an explicit check to see if an element is present before using this element in the next command (which may lead to an error and disrupt script execution). The "sideflow" user extension allows you to perform conditional jumps inside your code.

Here is the side stream extension home page: https://github.com/darrenderidder/sideflow

With the side stream extension, you can use the following code:

storeElementPresent id=btnRecSearch isPresent gotoIf ${isPresent} == false End click id=btnRecSearch .... label End 
+11
source

If you use the entire verify command, then your script does not stop if the element is not found using the seleniun IDE, but if you use the associated assert command, then your script stops if this element is not found by selenium ide

If you need to create your script using the verifytext , then run the script and you will see that your script will not stop if the element is not displayed

+2
source

You can also use the Selblocks plugin, which implements the catch method, to catch the error and continue the script anyway. try / catch / finally block An attempt can provide special handling when an error occurs and can guarantee the execution of, for example, the "clear" logic.

The catch block indicates what to do if an error is selected in the try block. That is, if an operator in a try block or in a function or subfunction called from a try block throws an error, then control passes to the corresponding catch block and the error is cleared. If an error does not occur in the try block, then the catch block is skipped. Catch intercepts the given error by matching its error message, which is indicated as a "substring" or as / regular expression /. Lack of specification will catch all errors.

The finally block is executed after the try and catch blocks. It always runs regardless of whether an error is selected or not. It is executed even if the try or catch block is completed using the "change flow" commands: the continue, break, return, or exitTest commands.

Lock attempts may be nested. If the internal attempt does not catch the error, the attached try / catch is entered. The contents of all nested blocks (blocks) are finally completed, the most internal - external - again, even if errors (errors) are encountered along this path.

Both catch and, finally, are optional, but if they are not specified, the attempt simply has no effect.

An optional identifier can be specified in try and endTry, which will be checked for proper pairing.

Try / catch / finally example try | outdoor try | domestic quit | "blamo" getEval | alert ("this warning will NOT be executed") eventually getEval | alerts ("first") endTry | internal catch | / blamo / getEval | alerts (second) endTry | outdoor you can read here http://refactoror.wikia.com/wiki/Selblocks_Reference

+1
source

The Selenium IDE plugin is designed more for writing (i.e. showing you the code behind the actions); it allows some reproduction, but it is rather limited, and I'm not sure if it allows to handle errors. Now that you are ready to use actual programming, you can easily handle errors. For example, in Python, you can use something like this:

 try: driver.find_element_by_id("userid").click() except NoSuchElementException: # do something else (close page, give you a warning, etc) 
0
source

This is how I solved the problem, for example, using the SELECT command:

I created a custom trySelect command that acts like a regular SELECT but does not stop the check if the item cannot be found

1) create the file 'user-extensions.js' with the following code

 Selenium.prototype.doTrySelect = function(locator,target) { try { return Selenium.prototype.doSelect.call(this,locator,target); } catch(err) { return null; } }; 

2) in Selenium IDE => options => options => general: add your user-extensions.js file to the 3rd input, as shown below selenium option interface

3) restart the Selenium IDE

4) usage example (as usual SELECT)

 trySelect | //select | label=regexpi:.*Hey.* 

You can do the same for other commands that may fail, for example, click .

0
source

This example is for the new version 3 of Selenium IDE, which works in Firefox and Chrome. Basic premise:

1) store xpath count - this saves the number of elements that correspond to the variable

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

2) if - in this case, the check is greater than 0

 if | ${error} > 0 

3) do magic things

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/

0
source

I just want to continue my Selenium IDE script, even if no error or item was found.

Now it's very easy with the Kantu Selenium IDE : just use it ! Errorignore :

 Store | true | !errorignore 

And if you want to check later in your script whether there was an error and to do something with it, you only need to check the value ! StatusOK :

 If | ${!statusOK} == false | echo | handle error here endIF 
0
source
  • Open the page in your Mozilla and Selenium IDE browser.
  • Right-click the text and select waitForElementPresent .
  • The command is added to the recorded script.
  • When an item is verified and presented, the next command can either be pressed or printed according to the needs of users, and the target will always be the item identifier.
-one
source

Source: https://habr.com/ru/post/1498127/


All Articles