Open isaldarriaga opened 9 years ago
Hi @isaldarriaga There's no such thing as a stupid question! And dropdowns are a lot trickier with Selenium than one might expect.
On your Page Object, you have a couple of methods for selecting items in a dropdown, either by value or by text:
Input.SelectByOptionValueInDropDown(x => x.RequiredEnum, value);
Input.SelectByOptionTextInDropDown(x => x.RequiredEnum, value);
You can see them both illustrated in our acceptance tests, on this Page Object: https://github.com/TestStack/TestStack.Seleno/blob/master/src/TestStack.Seleno.AcceptanceTests/PageObjects/Form1Page.cs
And these two acceptance tests in this file: https://github.com/TestStack/TestStack.Seleno/blob/master/src/TestStack.Seleno.AcceptanceTests/PageObjects/Controls/IndividualWritingTests.cs
Selecting_option_by_its_value_in_a_Drop_Down Selecting_option_by_its_text_in_a_drop_down
Hope that helps.
Hi @mwhelan. thanks for your response.
I'm seeing in the test acceptance examples they're using strongly-typed page objects.
This is not my case. I just use weakly-typed ones and use Find.Element to look for controls by ID, name, etc.
When i try to assign the returned RemoteWebElement to a DropDown, i get a System.InvalidCastException. They shouldn't be compatible.
I'm new to the repo. Is there an example there with weakly typed?
thanks.
Try using
HtmlControlFor<DropDown>("nameOfSelectElement").SelectElementByText("Name of option to select");
// or
HtmlControlFor<DropDown>("nameOfSelectElement").SelectElement(value);
Thank you @robdmoore
It worked pretty well.
It would be helpful that HtmlControlFor<> receives a selector instead of an Id, and work similar to Find.Element
I couldn't find any documentation for this simple task.
I tried with click() over the control, but doesn't make the dropdown to display the options.
The selector is returning an OpenQA.Selenium.Remote.RemoteWebElement object.
thanks.