I want Selenium to choose an option but it didn't work for me I tried this
phone = Select(driver.find_element(By.NAME, "PhoneCountry"))
phone.select_by_data-value(self, US)
and it failed
And this is the html
CodePudding user response:
There is no such way to select option by_data-value
.
There only 3 ways:
- Select by index
- Select by visible text
- Select by value.
References:
official documentations
www.geeksforgeeks.org
So, instead of your code please try this:
phone = Select(driver.find_element(By.NAME, "PhoneCountry"))
phone.select_by_visible_text(self, "US")
I don't know what is the actual visible text there, it can be "US", or "USA" or something else.
CodePudding user response:
I found the solution
Select(driver.find_element_by_id("PhoneCountry")).select_by_visible_text(u"United States ( 1)")