-1

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.

1
  • 1
    Welcome. Next time, try to show us what you have done as well. People here should help you, not do the whole thing for you. – pavelsaman Jan 5 '20 at 12:01
1

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])
0

Use will need to use getOptions() method of Select Class in Selenium. This will return a List of WebElements in the dropdown

Sample Code for your reference :

Select optionSelect = new Select(driver.findElement(By.id("dropdown_cities")));
List <WebElement> elementCount = optionSelect.getOptions();

Now you can iterate over this list and assert values as per your preferance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.