How to select the checkbox in the first column depending upon the value of the third column

158 views
Skip to first unread message

Srihari Chatla

unread,
Mar 4, 2014, 7:13:07 AM3/4/14
to seleniu...@googlegroups.com
please see the images attached for the table and the html hirearchy.
aaa.jpg
aaaa.jpg

Saravanan Ravi

unread,
Mar 4, 2014, 9:54:43 AM3/4/14
to seleniu...@googlegroups.com
Hi,
 
By combining of For loop and If condition, we can achive that
 
for(int i=1; selenium.isElementPresent("//tr["+i+"]");i++)   //Verifying whether row is available or not
{
   if (selenium.getText("//tr["+i+"]/td[3]/span"),equals("888810002"))   //To get the text from the third column
    {
       selenium.check("//tr["+i+"]/td/input");
       break;
    }
}
 
Regards,
Saravanan R

Krishnan Mahadevan

unread,
Mar 4, 2014, 10:10:57 AM3/4/14
to Selenium Users
Saravanan,
I would personally not advise anyone to use any methods within DefaultSelenium [ selenium.isElementPresent(), selenium.getText(), selenium.check() methods ] because DefaultSelenium which belongs to Selenium1 has been deprecated long back and WebDriver is the way to go !

so I would replace selenium.isElementPresent() with webdriver.findElements(By.xpath("")).isEmpty() == false
selenium.getText() with webDriver.findElement(By.xpath("")).getText()
and selenium.check() with new Select(webDriver.findElement(By.xpath(""))).selectByXXXX(value);



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d12665f2-5441-457f-bea7-62b2c5b4d773%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Wojtek R

unread,
Mar 6, 2014, 4:44:29 AM3/6/14
to seleniu...@googlegroups.com

I think this will be right xpath for this (i don't test it):
//tr/td/span[text()='888810002']/../..//input[@type='checkbox']

so you can check (change status) checkbox by command:

driver.findElementByXPath("//tr/td/span[text()='888810002']/../..//input[@type='checkbox']").click();

i see the whitespace's in string so mayby you shoud use contains() xpath method:
//tr/td/span[contains(.,'10002')]/../..//input[@type='checkbox']

above method's are column undepend so you can use the text from 1st and 2nd column.

NANI.THRINATH

unread,
Apr 6, 2014, 5:59:56 AM4/6/14
to seleniu...@googlegroups.com
Krishnan: - .isEmpty(), will work ? it don't works for me. Am using 2.37

Regards,
Thrinath


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Regards,
Thirnath

Krishnan Mahadevan

unread,
Apr 6, 2014, 6:13:59 AM4/6/14
to seleniu...@googlegroups.com
You haven't told us a lot behind "it doesn't work"! 
So I don't quite know what I should be replying here. 

~ Krishnan

iSent. iPhone. iReget.iTypos!

Brian Kitchener

unread,
Apr 9, 2014, 1:00:32 PM4/9/14
to seleniu...@googlegroups.com
You can do this easily with nested xpath expressions.  We get a reference to the ancestor TR, then find its descendant checkbox.    //tr[.//span[text()='888810002']]//input[@type='checkbox']
Reply all
Reply to author
Forward
0 new messages