Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
kame
Posts : 2
Join date : 2011-02-21

iteration with xpath to an select  Empty iteration with xpath to an select

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;
            }
         }         
      }
[..]
avatar
Marthyn
Posts : 3
Join date : 2011-02-21

iteration with xpath to an select  Empty Re: iteration with xpath to an select

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

iteration with xpath to an select  Empty Re: iteration with xpath to an select

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

iteration with xpath to an select  Empty Re: iteration with xpath to an select

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