Here is my problem with these dropdowns of mine: As an automation tester, I have some issues using Selenium's "Select();" method 'bout dropdown fields. If I have to run a test in multiple cycles and select different option from the dropdown every next cycle- I just used Select(); method and it worked great. Now the problem is that in the HTML code I do not even see the option of the dropdown, the field is changed to dynamic, it is not static anymore. How can I work around this feature or is it just a bad programming practice? Thank You in advance!
CodePudding user response:
I think it's not bad practice to have dynamic options in a dropdown menu.
To write an end-to-end test for this it depends how dynamic these options are. If they change from release to release (e.g. the available product categories in the system), you should probably encode them in your test. In that way the test will have to be updated if the options are updated, which makes sense (the test will fail if it doesn't find the options it expects).
If the options change by external factors (e.g. the current top 10 trending topics on Twitter) then you cannot encode them in your test. You should then probably try to pick one by index (e.g. the first one) and parameterize the test to handle any value that might be there. Alternatively you could stub the 'TrendingValuesFromTwitterService' (staying with my example) to deliver a fixed set of values for your testing purposes.
CodePudding user response:
Normally static data with Select, Dropdown or combobox is a best practice. Unfortunately, sometimes we need dynamic data with Selects. The best way is that, you have to use Fluent Waits for Select contains your option. Also, Thread.sleep() is another solution but it is not preferable. However, it is exact solution. Try to implement, Fluent or Implicit waits for your select options. For ex; ElementToBeVisible or ElementToBeExists etc. Checkout : https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html