in reply to Re^4: Error Handling in Selenium
in thread Error Handling in Selenium
Hi Everyone, As you all suggested here is a small snippet
use strict; use warnings FATAL => 'all'; use Selenium::Remote::Driver; use Selenium::Chrome; use Selenium::Remote::WebElement; my $driver = Selenium::Chrome->new(binary=>"D:\\chromedriver_win32\\ch +romedriver.exe"); $driver->maximize_window(); $driver->set_implicit_wait_timeout(1000); $driver->get('http://google.com'); $driver->pause(2000); $driver->find_element_by_xpath(".//*[\@id='lst-ib']")->send_keys('perl +monks'); $driver->pause(5000); print "1"; #The below line is just for testing that what happens if element is no +t present.And it even gives no warning or anything. $driver->find_element_by_xpath("abc"); $driver->pause(5000); print "2"; #The below line is just for testing that what happens if element is no +t present. This gives a warning as stated in below para. $driver->find_element_by_xpath("def")->click; $driver->pause(5000); $driver->find_element_by_xpath(".//*[\@id='sblsbb']/button")->click; $driver->pause(5000); $driver->shutdown_binary;
So in the above snippet which is for searching something in Google. The lines $driver->find_element_by_xpath("abc"); and $driver->find_element_by_xpath("def")->click; are just added to check what happens for elements not present.
The command prompt shows the error Use of uninitialized value in substitution iterator at C:/Perl/site/lib/Selenium/Remote/Commands.pm line 437.. That too is only for the one on which click is also defined. How can I catch these to call another sub for sending notification mails. Also please let me know how can I catch error for the line with no click element as it is not even giving any warning in the Prompt.
One more thing the Output for above throws the warning first then 1 and 2. Is it always that warnings are thrown first not depending on the line by line execution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Error Handling in Selenium
by haukex (Archbishop) on Nov 21, 2016 at 16:54 UTC | |
by 9mohit2 (Sexton) on Nov 22, 2016 at 06:59 UTC | |
by Anonymous Monk on Nov 22, 2016 at 07:55 UTC |