sagarpabba / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

Errors handling while running Subroutines with Selenium Webdriver #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

1) Is there a way to handle Timeout errors connected to Selenium macros?

I occasionally get the following error, mostly caused by poor internet 
connection or issue with Mozilla:

    Run-time error'-2146232832 (80131600)':

    Method <start> failed ! Timeout reached.

http://imageshack.us/photo/my-images/444/problemkd.jpg/

Pls could you provide example of code repeat the last selenium command that 
caused the timeout error after say 10s?

2) There was a number of times that Selenium Crashed when I tried to run a 
command that simply was invalid, 
- instead I would like Excel to skip this line, and carry on with remaining 
code.

Pls consider the following example:

I am sometimes having to close confirmation pages, ( by running selenium.Click 
"css=input.bossubmit" ) 
but don't know how many of them I need to click on Sometimes I need to on 1, 
sometimes 2, sometimes none of the confirmations.

However trying to close the confirmations in a loop as below causes the Excel 
to crash:

  For i = 1 To 2

  selenium.Click "css=input.bossubmit"

  On Error GoTo finish
  Next i

finish:

Pls could you provide a piece of code how to handle this problem?

Original issue reported on code.google.com by grzegorz...@gmail.com on 15 Aug 2012 at 10:24

GoogleCodeExporter commented 9 years ago
> Is there a way to handle Timeout errors connected to Selenium macros?
You can check the error and try again in a loop as foolow :

    Dim selenium As New SeleniumWrapper.WebDriver 
    On Error Resume Next    'To ignore errors 
    Do 
        If Err.Number <> 0 Then selenium.Wait 10000 'waits 10s in case of error 
        Err.Clear   'Clear errors
        selenium.Start "firefox", "http://www.google.com" 
    While Err.Description Like "*Timeout*" ' Check for a timeout error in the error message 
    On Error GoTo 0    ' Cancel resume next on error

> Pls could you provide a piece of code how to handle this problem?
The best way is to loop on the element while it is present and to delete it :

    Do While selenium.isElementPresent("css=input.bossubmit") 
      selenium.Click "css=input.bossubmit" 
      selenium.Wait 100 
    Loop

Original comment by florentbr on 20 Aug 2012 at 3:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by florentbr on 10 Sep 2012 at 11:13

GoogleCodeExporter commented 9 years ago

Original comment by florentbr on 8 Sep 2014 at 5:35

GoogleCodeExporter commented 9 years ago
Hello, really enjoy using the selenium tool and I know of many enterprises 
using you code.

In your Aug 20, 2012 reply, I was wondering where the End If for the "If 
Err.Number <> 0 then.." terminates at?

If Err.Number <> 0 Then selenium.wait 10000 
End If
Err.Clear .....

or are "Err.Clear" and "selenium.Start" are nested in the If statement
If Err.Number <> 0 Then selenium.wait 10000 
Err.Clear
selenium.Start
End If

Thank you,

Original comment by mhernand...@gmail.com on 21 Jan 2015 at 9:49

GoogleCodeExporter commented 9 years ago
In VB, the "End If" statement is not required when the code is on the "If" line 
and only the code on this line will be executed if the condition is true.

 If 1 = 1 Then Debug.Print "true"

is the same as :

 If 1 = 1 Then
   Debug.Print "true"
 End If

Original comment by florentbr on 22 Jan 2015 at 9:39