- kame
- Posts : 2
Join date : 2011-02-21
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 :
Do anyone know what could be the problem or find another way to get to all the "SELECT" elements ?
More code for that problem:
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 +"]")){
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
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
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.
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);
- how to select button like filed embeded in div tag in webpage using xpath
- How Xpaths works in Selenium and What is the difference between native Xpath and absolute xpath and relative xpath.
- Select the “back” button of the Firefox browser to right click and Select the Option from the right click Menu in Selenium Web Driver - Java
- how to select an option from select box of a form
- Iteration in Selenium
Permissions in this forum:
You cannot reply to topics in this forum