0

This page page has a list of phone codes, I need to change the selected country code, it can be done by adding this

        <option value="ua">380+ country</option>
        <option value="ug">256+ country</option>
--->    <option value="uk" **selected**="">44+ country</option>
        <option value="uy">598+ country</option>
        <option value="uz">7+ country</option>
        <option value="ve">58+ country</option>
        <option value="vn">84+ country</option>
        <option value="ws">685+ country</option>
        <option value="ye">967+ country</option>
        <option value="yu">381+ country</option>
        <option value="za">27+ country</option>

so how can I write 'selected' anywhere I want with selenium?

Ayan Adel
  • 29
  • 6
  • one way I can think of is to get the whole html document, and then string format it, then run it locally, so as an html document it will at least have the visual appearance – Matiiss Jul 12 '21 at 08:38
  • can this be an answer [here](https://stackoverflow.com/questions/39543237/python-selenium-modifying-the-source-code-of-a-webpage) – Ayan Adel Jul 12 '21 at 08:41

1 Answers1

2

You have shown only options tag from HTML structure.

They must be child of Select tag in HTML.

Basically Select and option tags are meant to build a drop down.

You can select them like this :

menu = Select(driver.find_element(By.XPATH, "xpath of select web element"))
menu.select_by_value("ua")
cruisepandey
  • 28,520
  • 6
  • 20
  • 38