Is using the Select element instead of physically doing 'element.click()' bad practice in Test Automation?

Viewed 57

Is using the Select element instead of physically doing 'element.click()' bad practice in Test Automation?

I am concerned if we should even be using <select> elements since we are essentially bypassing the UI? Struggling to find discussions relating to this.

1 Answers

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:

Related