Is using the Select element instead of physically doing 'element.click()' bad practice in Test Automation?
html-select nodes must be always handled through Select(webelement)
class inducing WebDriverWait for the element_to_be_clickable()
. As an example:
Using Java, cssSelector and
selectByVisibleText()
:new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("selectElementCss")))).selectByVisibleText("visibleText");
Using Python, xpath and
select_by_value()
:Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "select_element_xpath")))).select_by_value("option_value")
References
You can find a couple of detailed discussions in:
- How to open the option items of a select tag (dropdown) in different tabs/windows?
- How to select an option from a dropdown through Selenium WebDriver
- How to select a drop-down menu value with Selenium using Python?
- Message: Element could not be scrolled into view while trying to click on an option within a dropdown menu through Selenium