3

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
gregbanham
  • 31
  • 2

1 Answers1

0

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 3
    Sorry I should have clarified. Iv never seen a select element on its own in the wild, it always has labels that can expand the dropdown list and
  • tags for the items in the list. This feels like a better approach as I am actually testing the UI interactions, instead of interacting with it programmatically (which I think SelectElement.selectByValue("test") does).
  • – gregbanham Dec 22 '20 at 12:05