Click on a child item in a web table, by iterating each row - QTP and Selenium

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Click on a child item in a web table, by iterating each row - QTP and Selenium

Illusion0Reality
This post was updated on .
Not sure, this is much useful or not, but should be handy  sometimes, I think.
Tarun helped me in this issue.

The code has been verified.

QTP
We should use
IF ChildItemCount(row,column,”Link”) > 0 then:
Set cobj = B.P.Webtable().ChildItem(r,c,”Link”,0)
cobj.Click



SELENIUM :  
public void clickALink()
throws Exception
{
boolean clicked =false;
boolean clicked1st=false;
int rc = selenium.getXpathCount("//table[contains (@class,'data')] /tbody/tr").intValue();
int cc = selenium.getXpathCount("//table[contains (@class,'data')] /tbody/tr[2]/td").intValue();

for (int r=1;r<=rc;r++)
{
for (int c=4;c<=cc;c++)
{
String t= driver.findElement(By.xpath("//table[contains (@class,'data')]/descendant::tr["+r+"]/td["+c+"]")).getText();
System.out.println(t);
if (t.contains("CNO112223"))
{ driver.findElement(By.xpath("//table[contains (@class,'data')]/descendant::tr["+r+"]/td[ "+c+"]")).click();
Thread.sleep(11);
clicked1st=true;
}
if (clicked1st)
{
String u= driver.findElement(By.xpath("//table[contains (@class,'data')]/descendant::tr["+(r+1)+"]/td["+c+"]")).getText();
if (u.contains("NNO112223"))
{
driver.findElement(By.xpath("//table[contains (@class,'data')]/descendant::tr["+(r+1)+"]/td["+c+"]")).click();
Thread.sleep(11);
clicked=true;
}
}
Thread.sleep(11);
if (clicked)
{break;}
}
//rows loop
}

Reply | Threaded
Open this post in threaded view
|

Re: Click on a child item in a web table, by iterating each row - QTP and Selenium

softwaretestingforum
Administrator
Thanks for sharing this.
~ seleniumtests.com