In the web application you are testing, you need to select several options in a dropdown menu
Which of the following is the BEST approach for selecting a dropdown option using WebDriver?
- Use the switch_to class to switch to the dropdown element, and then click on the option in the dropdown
- Click on the dropdown option using its relative XPath
- Click on the dropdown option using its absolute XPath
- Click on the dropdown element and then click on the option in the dropdown
Answer(s): D
Explanation:
This approach directly interacts with the dropdown element and then the option within it. Using relative or absolute XPath can work but they may become brittle if the web page structure changes. The switch_to class is mainly used to switch between the different frames and windows, it's not the best approach for this scenario.
Reveal Solution Next Question