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
Jeeva patrose
Posts : 8
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Webdriver code for dropdown selection is not working

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
avatar
Love Sharma
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

Fri Jun 01, 2012 12:39 pm
Pls provide the error details as well
avatar
saleem
Posts : 8
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

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.
avatar
Love Sharma
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

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);
}
avatar
Jeeva patrose
Posts : 8
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

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

avatar
Love Sharma
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

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
avatar
Jeeva patrose
Posts : 8
Join date : 2012-06-01

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

Tue Jun 12, 2012 3:05 pm
Thank you.

The code is working fine.
Sponsored content

Webdriver code for dropdown selection is not working Empty Re: Webdriver code for dropdown selection is not working

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