Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Error Handling in Selenium

by GotToBTru (Prior)
on Oct 05, 2016 at 18:33 UTC ( [id://1173358]=note: print w/replies, xml ) Need Help??


in reply to Error Handling in Selenium

Without code, it's hard to guess. Perhaps turn debug_on to gain additional insight?

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Replies are listed 'Best First'.
Re^2: Error Handling in Selenium
by 9mohit2 (Sexton) on Nov 17, 2016 at 07:39 UTC

    Why is eval block not working in the code below :

    eval{$elem = $driver->find_element(".//*[\@id='nav']/li[3]/a");} if($@){ print "Erro Occured"; }

    I am not getting any ways to throw immediate error if an element is not found.

      Hi 9mohit2,

      Your question is unclear because you don't say how your code is "not working" and what you would like your code to do. Also note that the better way to use eval is eval { ...; 1 } or do { print "Error: $@"; };, as explained in Bug in eval in pre-5.14.

      In the code you showed, eval will trap any errors, such as from die, thrown by the code inside the eval, which you can then handle in any way you want. If you remove the eval, then an error in find_element should instead cause your script to die. If this is not happening, then perhaps the function is not throwing an error, or you have some other kind of error handling already in place.

      On the other hand, if by "immediate error", you mean you want the code to throw an error, as you also seem to be saying in the OP, and find_element is not throwing an error, then you will have to inspect the return value of the function. One thing you could do is inspect it with Data::Dumper, to see what kind of values the function returns under various conditions, that should help you decide on the conditions in which you'd like to throw your own error.

      In general it would be better if you could be more clear on what you mean with "not working", i.e. what the expected vs actual behavior is, with code examples. See I know what I mean. Why don't you? and How do I post a question effectively?

      Hope this helps,
      -- Hauke D

        Hi Hauke, Sorry for the "not working" thing. The problem I am facing is find_element throws error which are captured by the Webdriver prompt but it does not throws error to the command prompt and execution goes till the end of script. So I wanted a way so that the script stops execution if any element is not found. Can you please suggest any way of doing so as I have seen posts were eval is being used in this sense only but it did not work on mine.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found