Reputation: 2177
How to read all values of dropdown in Selenium IDE?
I have a dropdown which have values in it (for eg Dates), I need to select each value and click on submit button and generate the report again select the next value... the loop continues till the end of dropdown values.
How can i do this with Selenium IDE?
Upvotes: 1
Views: 1976
Reputation: 1105
This is a little tricky to achieve elegantly within Selenium-IDE. As Apjuh mentioned, a loop would be the best way to select each value. Unfortunately, Selenium-IDE does not have any flow control commands by default. There are two choices here:
1) Implement every iteration of the loop manually. Not recommended.
2) Download and install the Flow Control plugin for Selenium-IDE. I don't have any experience using it myself, but I might try it for a bit now and report back with results.
From there, it ought to be possible to construct a loop that does what you need to do.
Edit: After having done battle with Selenium-IDE for the last half-hour, I can only conclude that Selenium-IDE probably isn't the best tool for the job here! The following commands do successfully imitate a for
loop:
store | 0 | i
label | loopStart
getEval | alert("i = " + storedVars.i)
store | javascript{storedVars.i++;}
gotoIf | storedVars.i < 4 | loopStart
...but getting it to play well with a dropdown box (e.g. selecting the option at index i
) was proving problematic and ultimately far too much hassle for what should be a simple task. If at all possible, I think it would be worth looking into Selenium WebDriver, which would allow the use of actual code. Using C#, Apjuh's answer would perform the job perfectly well, and I imagine it didn't take him half an hour to get that far!
Upvotes: 1
Reputation: 41
You can use a loop, the loop will cycle through the option in the dropdown.
List<WebElement> dropdown = driver.findElements(locator));
for(WebElement t : dropdown) {
String valueText = t.getText();
Select value = new Select(driver.findElement(locator);
value.selectByVisibleText(valueText);
buttonSubmit.click;
}
Upvotes: 1