[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Mojo::DOM CSS selectors sure are handy
http://deafferret.tumblr.com/
Really enjoying the Mojo::DOM bit of Mojo, from the Mojolicious family of software, which I’ve never used before today. Drops nicely into Test::WWW::Mechanize :)
The problem:
For a series of websites, for a series of item numbers, if there’s a “choose your item” table then make sure there are quantity_input fields too:
The solution:
my $mech = Test::WWW::Mechanize->new;
foreach my $base (@base) {
foreach my $i (@item_nums) {
$mech->get_ok(item_url($base, $i));
diag("$i: " . $mech->title);
my $dom = Mojo::DOM->new($mech->content);
SKIP: {
skip "has no 'choose your item' table", 1 unless
$dom->find('table#chooseYourItem')->size;
ok($dom->find('input.quantity_input')->size, "has grid qty inputs");
}
}
}
Slick! :)
Luis Roman wrote a much longer article about this, if you’re interested.
http://deafferret.tumblr.com/