- Jeeva patrose
- Posts : 8
Join date : 2012-06-01
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
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
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
- Love SharmaRegular Participant
- Posts : 27
Join date : 2012-06-01
Re: Webdriver code for dropdown selection is not working
Fri Jun 01, 2012 12:39 pm
Pls provide the error details as well
- saleem
- Posts : 8
Join date : 2012-06-01
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.
use this above method to select a one value from dropdown box.
If you want access more values use the Xpath.
- Love SharmaRegular Participant
- Posts : 27
Join date : 2012-06-01
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);
}
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);
}
- Jeeva patrose
- Posts : 8
Join date : 2012-06-01
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.
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
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();
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
- Love SharmaRegular Participant
- Posts : 27
Join date : 2012-06-01
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
Select select = new Select(driver.findElements(By.id("option")));
select.selectByVisibleText(valToBeSelected);
Thanks,
Lovekesh
- Jeeva patrose
- Posts : 8
Join date : 2012-06-01
Re: Webdriver code for dropdown selection is not working
Tue Jun 12, 2012 3:05 pm
Thank you.
The code is working fine.
The code is working fine.
Permissions in this forum:
You cannot reply to topics in this forum