Share
Go down
Bhuvaneswari
Regular Participant
Regular Participant
Posts : 30
Join date : 2011-09-30
Location : India

Multiple choice selection using RC

on Mon Jan 16, 2012 12:00 pm
Hello,

I have a table with number of columns. First column has check boxes for each row, second column has the name of the item(unique). I wanted to select/deselect the check box by pointing to the name of the item where the items name can be static as well as dynamic. Assume I know the name of the item. Please let me know how to achieve this ?
Thanks
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: Multiple choice selection using RC

on Mon Jan 16, 2012 2:57 pm
I have got a solution for this issue.
You searching all items in the table in 'for' loop and find the item which you want to select. You can use 'if' statement. When you find the item, you will have a row number and could select / unselect checkbox.

Code:
for ($i = 1; $i <= $this->getXpathCount("//table/tbody/tr"); $i++) {
    if ($this->getText("//table/tbody/tr[$i]/td[2]") == $nameOfItemYouWantToSelect) {
        $this->click("//table/tbody/tr[$i]/td[1]/input[@type='checkbox']");
    }
}
Bhuvaneswari
Regular Participant
Regular Participant
Posts : 30
Join date : 2011-09-30
Location : India

Re: Multiple choice selection using RC

on Wed Jan 25, 2012 5:32 pm
Thanks. Was sometime into Web Driver and today I tried this solution you gave. I am not able to find the element using this XPATH. I tried both with absolute as well as relative path but failed to identify the text associated with it.

Any idea on this kind of problem ?
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: Multiple choice selection using RC

on Wed Jan 25, 2012 5:37 pm
Message reputation : 100% (1 vote)
Did you try with the other xPath? You can check it using xPath Checker (Firefox plugin).
Bhuvaneswari
Regular Participant
Regular Participant
Posts : 30
Join date : 2011-09-30
Location : India

Re: Multiple choice selection using RC

on Wed Jan 25, 2012 5:59 pm
Yeah I recently added that XPath plugin to my browser and it's really helpful.

Please find the XPath values for the elements I have,

The XPath for the checkbox of the row-1:column-1,

Code:
html/body/div[3]/div[2]/div/div/div/div[1]/section/div/div/div/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div/div[2]/div[4]/div[4]/div[2]/div[2]/div/table/tbody/tr/td[1]/div/div/input

The XPath of the cell having the unique text of row-1:column-2,

Code:
html/body/div[3]/div[2]/div/div/div/div[1]/section/div/div/div/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div/div[2]/div[4]/div[4]/div[2]/div[2]/div/table/tbody/tr/td[2]/div

Tried,
Code:

for(int i=1; i<=(Integer)selenium.getXpathCount("//html/body/div[3]/div[2]/div/div/div/div[1]/section/div/div/div/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div/div[2]/div[4]/div[4]/div[2]/div[2]/div[1]/table/tbody/tr"); i++) {
            if(selenium.getText("//html/body/div[3]/div[2]/div/div/div/div[1]/section/div/div/div/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div/div[2]/div[4]/div[4]/div[2]/div[2]/div[1]/table/tbody/tr["+i+"]/td[2]").equalsIgnoreCase("<matching-text>")) {
                selenium.click("//html/body/div[3]/div[2]/div/div/div/div[1]/section/div/div/div/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div/div[2]/div[4]/div[4]/div[2]/div[2]/div[1]/table/tbody/tr["+i+"]/td[1]/div/div/input[@type='checkbox']");
               
            }
        }
Bhuvaneswari
Regular Participant
Regular Participant
Posts : 30
Join date : 2011-09-30
Location : India

Re: Multiple choice selection using RC

on Fri Feb 03, 2012 11:49 am
Thanks a lot. Finally I got it working.

But my scenario is like I have number of frames added to my web page. The frames location differ based on which is opened first. And because of this the xpath differs for different scenarios.

Any idea on how we can handle this xpath varying scenario please ?
Sponsored content

Re: Multiple choice selection using RC

Back to top
Permissions in this forum:
You cannot reply to topics in this forum