Selenium: Select by number within span element

Issue

All avaible sizes had same class but I need to select by numbers in span.
I tried by doing this, but select function dont work with span element.

Code trials:

SIZECHOOSE=Select(driver.find_element(By.CLASS_NAME,"RYghuO._7Cm1F9.dgII7d.pVrzNP"))
SIZECHOOSE.select_by_visible_text("41")

Snapshot of HTML:

Code of website Zalando

Solution

As the element is not a element so you won’t be able to use the Select() class.

To click on a any specific number you can use either of the following Locator Strategies:

  • Using xpath and normalize-space():

    driver.find_element(By.XPATH, "//span[normalize-space()='42']").click()
    
  • Using xpath and contains():

    driver.find_element(By.XPATH, "//span[contains(., '42')]").click()
    

Answered By – undetected Selenium

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published