no warnings;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new;
$driver->get('https://www.crawler-test.com/');
$driver->find_element_by_xpath('//a[.="text not found"]');
How can I get the above code not to print this warning:
Error while executing command: no such element: Unable to locate element: //a[.="text not found"]
According to the docs, the function issues a "warning" if there is no element found, but having no warnings;
in the script does not suppress it.
How can I suppress this "warning"?
Use
find_element
instead offind_element_by_xpath
. The former throws an exception instead of issuing a warning. You can catch these exceptions using the following wrappers:nf
stands for "non-fatal".Written for Selenium::Chrome, but should work with Selenium::Remote::Driver as well.