I want to add all the city names in a list, so that I can compare then in assert is not in unit test.
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])
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.