2

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

HTML of the page

2 Answers 2

2

There is no such way to select option by_data-value.
There only 3 ways:

  1. Select by index
  2. Select by visible text
  3. 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.

Sign up to request clarification or add additional context in comments.

4 Comments

didn't work for me This is the site signup.live.com/… I want to choose from the list a number Thank you
The link you shared doesn't contain any Select / drop list. Maybe it is on some more advanced step of creating Microsoft account?
Sorry, I forgot to tell you, you should press (Use a phone number instead)
I see.. I tried, so far with no success.. I will try again later. That's interesting! In case you got a solution before me - please let me know
0

I found the solution

Select(driver.find_element_by_id("PhoneCountry")).select_by_visible_text(u"United States ‏(‎+1)")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.