How to pass the xpath that is stored in variable?

my $V1 = $sel->get_text("//body[\@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/table/tbody/tr/td/div/div");
print($V1 . "\n");

When i execute the above command, i could print the v1 without error.

My aim is to print the such values ( say around 20). But xpath for each variable varies by the div element only (i.e., div element preeceeding table should be replaced by div[2], and div[2] should be replaced by div[3] in every iteration.

Following snippet does the replacing div[] element. But saying as invalid xpath.

my $xpath = q(//body[\@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/table/tbody/tr/td/div/div);  
for my $i (0,2) 
{     
my @nodes = split qr'/', $xpath;     
$nodes[16] .= "[$i]" unless 0 == $i;     
#say join '/', @nodes; }
my @somenames = join('/',@nodes);
#print "\n";
#print @somenames ;
foreach my $val (@somenames) {
    chomp($val);
    #my @new_arr = $sel->get_text($val);
    print "\n";
    print $val; ***this prints the xpath value which i needed***
    my $V1 = $sel->get_text("$val"); ***#i'm passing the same xpath here within double quotes but says as invalid xpath***
     print($V1 . "\n");
    my @new_arr = $sel->get_text("$val");
  } 
}

Am i following wrong way of passing xpath ? How can i do it ?

Answers


Compare your definition of the XPath string with mine in the previous answer. You inserted a backslash in front of the commercial-at that does not belong.


Need Your Help

How to use jquery ui slider to change the class of a div

javascript jquery css jquery-ui

<div id="slider" align="center" style="width:50%;margin-left:20%;" ></div>