as far as I understand, there is no way in selenium to get the response code of the website. How can I work it around to know if a website has sent me an error or exception without having to expect an element in the site and wait for it until it times out?
use strict;
use warnings;
use Selenium::Chrome;
use Selenium::Waiter qw/wait_until/;
my $chrome_driver_path = "./../../tools/drivers/chromedriver.exe";
my $driver;
my %settings = (
'binary' => $chrome_driver_path,
);
$driver = Selenium::Chrome->new(%settings);
print("Getting stackoverflow\n");
wait_until{$driver->get("https://www.stackoverflow.com")};
validate_site($driver);
print("Getting unexistent url of stackoverflow\n");
wait_until{$driver->get("https://www.stackoverflow.com/this-does-not-exists-and-returns-404")};
validate_site($driver);
sleep(20);
$driver->shutdown_binary;
sub validate_site{
my ($driver) = @_;
#if ($driver->something) {
# print("Looks good)\n");
#}else{
# warn("Error\n");
# }
}
Expected result:
Getting stackoverflow:
Looks good
Getting unexistent url of stackoverflow:
Error
PD: I want to use selenium because I´m working in websites with javascript and storing cookies through different views, this is just an example to illustrate the problem that could be solved with a curl, but is not the case in my project.