Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

iteration with xpath to an select

View previous topic View next topic Go down

iteration with xpath to an select

Post by kame 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;
            }
         }         
      }
[..]

kame

Posts : 2
Join date : 2011-02-21

Back to top Go down

Re: iteration with xpath to an select

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

Marthyn

Posts : 3
Join date : 2011-02-21

Back to top Go down

Re: iteration with xpath to an select

Post by kame 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);
            

kame

Posts : 2
Join date : 2011-02-21

Back to top Go down

Re: iteration with xpath to an select

Post by Sponsored content


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