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


In reply to Re^3: Error Handling in Selenium by haukex
in thread Error Handling in Selenium by 9mohit2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.