How to add elements in list from a dropdown using Selenium/Python



  • enter image description here

    I want to add all the city names in a list, so that I can compare then in assert is not in unit test.



  • https://selenium-python.readthedocs.io/locating-elements.html

    The above link gives the selenium documentation for python. I Believe that you are trying to get all the text in option tag and store it in a list

    To get the text from multiple elements use below code:

    a= driver.find_elements(By.XPATH, '//select[@name="fromPort"]/option').text;
    print(a);
    

    or ( If above code doesn't work)

    elm= driver.find_elements(By.XPATH, '//select[@name="fromPort"]/option');
    print([elm.text for elm in elems])
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2