Issue
I am using Python and Selenium to add certain information to a form.
In this case, I need to insert the city of residence, selecting it from an auto-complete drop-down menu.
Altough the list is dynamic and may change depending on other values, to illustrate, I would like to select "Roma".
How can I effectively find and select a value from a list that is dynamically changing, using Selenium?
I tried with the methodology explained here, but the following error is reported:
UnexpectedTagNameException: Select only works on <select> elements, not on <input>
Snippets of the html code from the page are the following:
<input autocomplete="off" placeholder=" " id="dx_dx-e8acb639-2bdd-7dda-710a-2d81f408dc73_ComuneNascitaPk" class="dx-texteditor-input" aria-haspopup="listbox" aria-autocomplete="list" type="text" spellcheck="false" tabindex="0" role="combobox" aria-expanded="false" aria-required="true">
From the expanded list:
<div class="dx-scrollview-content" style="transform: translate(0px, 0px);"><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Affile</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Agosta</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Albano Laziale</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Allumiere</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Anguillara Sabazia</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Anticoli Corrado</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Anzio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Arcinazzo Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ardea</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ariccia</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Arsoli</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Artena</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Bellegra</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Bracciano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Camerata Nuova</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Campagnano di Roma</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Canale Monterano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Canterano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Capena</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Capranica Prenestina</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Carpineto Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Casape</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Castel Gandolfo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Castel Madama</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Castel San Pietro Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Castelnuovo di Porto</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Cave</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Cerreto Laziale</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Cervara di Roma</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Cerveteri</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ciampino</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ciciliano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Cineto Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Civitavecchia</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Civitella San Paolo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Colleferro</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Colonna</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Fiano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Filacciano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Fiumicino</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Fonte Nuova</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Formello</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Frascati</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Gallicano nel Lazio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Gavignano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Genazzano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Genzano di Roma</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Gerano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Gorga</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Grottaferrata</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Guidonia Montecelio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Jenne</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Labico</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ladispoli</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Lanuvio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Lariano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Licenza</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Magliano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Mandela</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Manziana</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Marano Equo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Marcellina</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Marino</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Mazzano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Mentana</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Monte Compatri</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Monte Porzio Catone</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Monteflavio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Montelanico</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Montelibretti</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Monterotondo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Montorio Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Moricone</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Morlupo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Nazzano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Nemi</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Nerola</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Nettuno</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Olevano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Palestrina</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Palombara Sabina</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Percile</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Pisoniano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Poli</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Pomezia</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Ponzano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Riano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rignano Flaminio</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Riofreddo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rocca Canterano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rocca di Cave</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rocca di Papa</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rocca Priora</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Rocca Santo Stefano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Roccagiovine</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Roiate</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Roma</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Roviano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Sacrofano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Sambuci</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">San Cesareo</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">San Gregorio da Sassola</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">San Polo dei Cavalieri</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">San Vito Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Santa Marinella</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Sant'Angelo Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Sant'Oreste</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Saracinesco</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Segni</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Subiaco</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Tivoli</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Tolfa</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Torrita Tiberina</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Trevignano Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Vallepietra</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Vallinfreda</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Valmontone</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Velletri</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Vicovaro</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Vivaro Romano</div></div><div class="dx-item dx-list-item" role="option" aria-selected="false"><div class="dx-item-content dx-list-item-content">Zagarolo</div></div></div>
Solution
You really can't use Select
class since you're trying to handle div
node not select
node...
You can use this approach to select reqired value
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Add code for clicking on input field to expand drop-down menu
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@role='option' and .='Roma']"))).click()
Answered By - JaSON
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.