Reputation: 1
I want to know how to select a particular row from a table, shown in a gadget.
On automating am getting the following code:
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*chrome",
browser_url => "http://10.102.163.3/" );
$sel->open_ok("/admin_ui/svm/html/main.html");
$sel->click_ok("//table[1]/tbody/tr/td[1]/div/table/tbody/tr/td[2]/img");
$sel->click_ok("//input[\@value='Yes']");
Can anyone please explain the following line in the above coding?
$sel->click_ok("//table[1]/tbody/tr/td[1]/div/table/tbody/tr/td[2]/img");
Also, am getting the same recording, every time when i select a row and delete.
Can anyone please explain how to check for a particular value as shown in the above snapshot and then select that row and delete it?
Please explain me with code.
thanks in advance.
Upvotes: 0
Views: 394
Reputation: 4002
Can anyone please explain the following line in the above coding?
$sel->click_ok("//table[1]/tbody/tr/td[1]/div/table/tbody/tr/td[2]/img");
$sel
is a reference to an object of type Test::WWW::Selenium
->click_ok()
invokes the click_ok
method of that object.
The argument to this method is a locator
"//table[1]/tbody/tr/td[1]/div/table/tbody/tr/td[2]/img"
is an xpath expression that specifies the HTML element to be acted on.
//
indicates that the locator type is an xpath expression.
table[1]
specifies the first occurence of a table (where there may be several successive tables)
...
td[2]
specifies the second occurence of a table data element.
The other parts should be obvious. Overall it specifies an image in the second column of a nested table.
(Update)
Can anyone please explain how to check for a particular value as shown in the above snapshot and then select that row
To select a tr
that contains an element with an attribute named value
with a value of "Yes"
you can use
//*[@value="Yes"]/ancestor::tr
I use the following code to test xpath expressions
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $xml = <<END; <table> <tr> <td>Foo</td> <td><input value="Yes" /></td> </tr> <tr> <td>bar</td> <td><a href="/woo.html">Woo</a></td> </tr> </table> END my $xpath = '//*[@value="Yes"]/ancestor::tr'; my $parser = XML::LibXML->new; my $doc = $parser->parse_string($xml); my $n = 0; for my $node ($doc->findnodes($xpath)) { print ++$n, ': ', $node->toString(), "\n"; }
Upvotes: 3