Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Webdriver code for dropdown selection is not working

View previous topic View next topic Go down

Webdriver code for dropdown selection is not working

Post by Jeeva patrose on Fri Jun 01, 2012 11:29 am

Hi,

I am using the below code in Selenium Webdriver-JUNIT for selecting the list of values from dropdown





import
java.util.List;
import org.openqa.selenium.WebElement;





public
static void selectValue(String valToBeSelected){


List options =
driver.findElements(By.id("option"));



for (WebElement option : options)
{



if
(valToBeSelected.equalsIgnoreCase(option.getText())){



option.click();


}


}


}



whereas I am getting error while executing the code. I am passing the "dropdown" field's id in driver.findElements(By.id("option"));

Please help me in resolving this issue.


Thanks in Advance,
Jeeva

Jeeva patrose

Posts : 8
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Love Sharma on Fri Jun 01, 2012 12:39 pm

Pls provide the error details as well

Love Sharma
Regular Participant
Regular Participant

Posts : 27
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by saleem on Fri Jun 01, 2012 6:19 pm

new select(driver.findElement(BY.id("schour").selectByVisibleText("04");
use this above method to select a one value from dropdown box.


If you want access more values use the Xpath.

saleem

Posts : 8
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Love Sharma on Fri Jun 01, 2012 6:45 pm

Hi,
Though to your understand your code issue, we would need the details of the error you are facing. But for an alternate solution of your requirement, please try below code...it should work:

public static void selectValue(String valToBeSelected)
{
Select select = new Select(driver.findElements(By.id("option")));
select.selectByVisibleText(valToBeSelected);
}

Love Sharma
Regular Participant
Regular Participant

Posts : 27
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Jeeva patrose on Fri Jun 01, 2012 7:42 pm

Thanks a lot for the Info.
We are trying to get the all list of values from the drop down box and need to verify that all the values are correctly loaded or not.We used the below code but we failed to analyze this code itself.





List options =
driver.findElements(By.tagName("option"));

for (WebElement option :
options) {



System.out.println(String.format("Value
is: %s", option.getAttribute("value")));
option.click();





And also we tried to execute the line of code options.getsize();
Here we are getting the size value only one, even though drop down box contains more than one value. And also we tried to get all the values but it is printing only the first value.
options.ContainsAll()--Its also not returning list of values from drop down box.

Could you suggest the code .. which helps us.. to get the all list of values from drop down


Jeeva patrose

Posts : 8
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Love Sharma on Fri Jun 01, 2012 7:55 pm

Try the belowgiven code...it will work

Select select = new Select(driver.findElements(By.id("option")));
select.selectByVisibleText(valToBeSelected);

Thanks,
Lovekesh

Love Sharma
Regular Participant
Regular Participant

Posts : 27
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Jeeva patrose on Tue Jun 12, 2012 3:05 pm

Thank you.

The code is working fine.

Jeeva patrose

Posts : 8
Join date : 2012-06-01

Back to top Go down

Re: Webdriver code for dropdown selection is not working

Post by Sponsored content Today at 4:59 am


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