Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Multiple choice selection using RC

View previous topic View next topic Go down

Multiple choice selection using RC

Post by Bhuvaneswari 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

Bhuvaneswari
Regular Participant
Regular Participant

Posts : 30
Join date : 2011-09-30
Location : India

Back to top Go down

Re: Multiple choice selection using RC

Post by faramka 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']");
    }
}

faramka
Professional
Professional

Posts : 143
Join date : 2011-09-15
Location : Poland

Back to top Go down

Re: Multiple choice selection using RC

Post by Bhuvaneswari 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 ?

Bhuvaneswari
Regular Participant
Regular Participant

Posts : 30
Join date : 2011-09-30
Location : India

Back to top Go down

Re: Multiple choice selection using RC

Post by faramka on Wed Jan 25, 2012 5:37 pm

Did you try with the other xPath? You can check it using xPath Checker (Firefox plugin).

faramka
Professional
Professional

Posts : 143
Join date : 2011-09-15
Location : Poland

Back to top Go down

Re: Multiple choice selection using RC

Post by Bhuvaneswari 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

Back to top Go down

Re: Multiple choice selection using RC

Post by Bhuvaneswari 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 ?

Bhuvaneswari
Regular Participant
Regular Participant

Posts : 30
Join date : 2011-09-30
Location : India

Back to top Go down

Re: Multiple choice selection using RC

Post by Sponsored content Today at 7:15 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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