Share
View previous topicGo downView next topic
kame
Posts : 2
Join date : 2011-02-21

iteration with xpath to an select

on Mon Feb 21, 2011 5:32 pm
Hi,

I'm trying to make selenium test for an dynamic created content (different element counts and ID's). With the test I want to find first SELECT that has not chosen value yet ("Please select") and hist ID contains "user_userprivassigns_attributes".

The problem is that getXpathCount returns for example 3 elements - and that is OK. The problem begins when I want to do anything on specified element from that list :
Code:
if(selenium.isElementPresent("//select[contains(@id, 'user_userprivassigns_attributes')]["+ i +"]")){
The element is not found !

Do anyone know what could be the problem or find another way to get to all the "SELECT" elements ?

More code for that problem:
Code:

[..]
int se = selenium.getXpathCount("//select[contains(@id, 'user_userprivassigns_attributes')]").intValue();
      
for(int i = 1; i <= se; i++){
      if(selenium.isElementPresent("//select[contains(@id, 'user_userprivassigns_attributes')]["+ i +"]")){
            String value = selenium.getSelectedLabel("//select[contains(@id, 'user_userprivassigns_attributes')]["+ i +"]");
                              
            if(value.compareTo("Please select") == 0)
            {            
               selenium.select("//select[contains(@id, 'user_userprivassigns_attributes')]["+ i +"]", "label="+ permission);
               sleep(1);
               break;
            }
         }         
      }
[..]
Marthyn
Posts : 3
Join date : 2011-02-21

Re: iteration with xpath to an select

on Mon Feb 21, 2011 9:15 pm
do you mean to get all the options in a select? Cause that is getSelectOptions("") i think
kame
Posts : 2
Join date : 2011-02-21

Re: iteration with xpath to an select

on Mon Feb 21, 2011 9:29 pm
No... I want to select a specific option with a specific label (stored in "permission" variable), but first I need to find out the proper SELECT element.
Currently with help of my friend I have fixed part of the problem - when I add "xpath=(...)[i]" then I can check if element is present, get selected label but not choose one option in the SELECT.

I still need to find a working way to run select function on one of the SELECT elements from few ones.

Code:

for(int i = 1; i <= se; i++){
                        //here I check if the element is present - this works now with the xpath=
         if(selenium.isElementPresent("xpath=(//select[starts-with(@id, 'user_userprivassigns_attributes')])["+ i +"]")){
                        //now I check if the SELECT has specific value ("Please select") - this also works with xpath=
            String value = selenium.getSelectedLabel("xpath=(//select[starts-with(@id, 'user_userprivassigns_attributes')])["+ i +"]");                               
            if(value.compareTo("Please select") == 0)
            {         
                                      //my current problem - here the xpath doesn't work. Without it only the fist element can be found and selection can be made.
               selenium.select("xpath=(//select[starts-with(@id, 'user_userprivassigns_attributes')])["+ i +"]", "label="+ permission);
            
Sponsored content

Re: iteration with xpath to an select

View previous topicBack to topView next topic
Permissions in this forum:
You cannot reply to topics in this forum