Reputation: 13
I'm trying to select one of the dropdown values, using this code, but nothing happens:
selectopt = Select(driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-bc-reservation/div/div[1]/div[1]/select'))
selectopt.select_by_value('1cfc3cd0ac77bba30ffac794183100dc220758511a6c943264f8273d90eb54c2')
Also tried select by:
select_by_visible_text
select_by_index
Nothing happens :(
Page HTML:
<select _ngcontent-plo-c48="" class="select-text smaller-text">
<option _ngcontent-plo-c48="" hidden="" disabled="" selected="" value=""></option>
<option _ngcontent-plo-c48="" value="1cfc3cd0ac77bba30ffac794183100dc220758511a6c943264f8273d90eb54c2"> Įgijimo deklaravimas/SDK gavimas</option>
<option _ngcontent-plo-c48="" value="bb3ad2ed220c6aeff347669b0eb5c55c756c0203ca2be2fffa02866a9f013e4a"> Perleidimo/sunaikinimo deklaravimas</option>
<option _ngcontent-plo-c48="" value="27b2dcd56aa0800fb8638add9a3924eef8100d3812503626d37101bbaa5efeb5"> Įgijimo perleidimo deklaravimas ir registracija Lietuvoje registruotos transporto priemonės (dalyvaujant pirkėjui ir pardavėjui)</option>
<option _ngcontent-plo-c48="" value="8729a97506baabbd88699aa7178c4993a00627f136e4438e074b20c4bcee2133"> Įgijimo perleidimo deklaravimas ir registracija iš užsienio įvežtos transporto priemonės (dalyvaujant pirkėjui ir pardavėjui)</option>
<option _ngcontent-plo-c48="" value="5df3a2ff0ca9261a8e455037be55bed969c21e6bc930b94ee0cd7f5428ebaa01"> Įgijimo perleidimo deklaravimas ir registracija naujų/laikinai registruojamų transporto priemonių (dalyvaujant pirkėjui ir pardavėjui)</option>
<option _ngcontent-plo-c48="" value="659b0032c6921eacb4e7fcf6b92cc48b584d2fdbd3231e2533a597113ce1e6a6"> Registracija Lietuvoje registruotos transporto priemonės</option>
<option _ngcontent-plo-c48="" value="6646155f52c6f27bb185bdd2c78549a2bac41356e37c4cacb7a668cdad80e3b3"> Registracija iš užsienio įvežtos transporto priemonės</option>
<option _ngcontent-plo-c48="" value="18dab62bb3aff0d11455560ee4e4031efdcf4e3c52101eabe3cf60261a058b79"> Registracija naujos (neregistruotos) transporto priemonės</option>
<option _ngcontent-plo-c48="" value="0360f75da4dcb6d941a0b15d3991397aaffe385883b582f0b2dc2678e00fbe79"> Registracija laikinai registruojamos transporto priemonės</option>
<option _ngcontent-plo-c48="" value="1f4be1860e622e43f8f24885662ab85904d59e1614464757cd78aab962b59f13"> Techninių duomenų keitimas</option>
<option _ngcontent-plo-c48="" value="9731f2a0c9dc91db96efaa9cb1bcb689dbcccc2bb17d4e57d4a2a89570c24b44"> Registracijos liudijimo keitimas</option>
<option _ngcontent-plo-c48="" value="7924d0491cc54487ca6efdf74fdf2e770db4f94a3f8d0d677e32be1528bbf370"> Leidimo dalyvauti viešajame eisme panaikinimas</option>
<option _ngcontent-plo-c48="" value="9e0a394249e8b8f04f14e2ace935b5cd41ac364f27590ea9cbe6a6ceafeaef3a"> Numerio ženklai</option>
<option _ngcontent-plo-c48="" value="1258ac903f436fae73ba186781b0d60601c7b9fe629777a1fb63ca70dd214314"> Pažymų išdavimas</option>
<!----></select>
Update:
Adding full code, with slight change, still the same problem.
Code directs you to the page, does some actions, and at the last page, I need this bot to select item from drop down list, but I'am unable to do it.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
driver.get('https://eregitra.lt/advance-reservation/service')
vehicRegBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-service/div/div/div/button[1]')
vehicRegBut.click()
OneVehicRegBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-service/div/div/div[1]/button')
OneVehicRegBut.click()
NatPersonBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div/div[1]/button[1]')
NatPersonBut.click()
Name = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[1]/input')
Name.send_keys('Name')
SurName = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[2]/input')
SurName.send_keys('Surname')
Email = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[3]/input')
Email.send_keys('[email protected]')
Tel = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[4]/div/input')
Tel.send_keys('65555560')
CheckBox = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[2]/div[1]/p-checkbox/input')
CheckBox.click()
NextBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[3]/div[2]/button')
NextBut.click()
selectopt = Select(driver.find_element_by_xpath("//select[contains(@class, 'select-text smaller-text')]"))
selectopt.select_by_index(2)
Upvotes: 1
Views: 196
Reputation: 29372
All it needed was explicit waits.
try this instead :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get("https://eregitra.lt/advance-reservation/service")
wait = WebDriverWait(driver, 10)
vehicRegBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-service/div/div/div/button[1]')
vehicRegBut.click()
OneVehicRegBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-service/div/div/div[1]/button')
OneVehicRegBut.click()
NatPersonBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div/div[1]/button[1]')
NatPersonBut.click()
Name = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[1]/input')
Name.send_keys('Name')
SurName = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[2]/input')
SurName.send_keys('Surname')
Email = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[3]/input')
Email.send_keys('[email protected]')
Tel = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[1]/div[4]/div/input')
Tel.send_keys('65555560')
CheckBox = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[2]/div[1]/p-checkbox/input')
CheckBox.click()
NextBut = driver.find_element_by_xpath('/html/body/app-root/html/body/div/div/div[2]/div/div/app-details/div/div[3]/div[2]/button')
NextBut.click()
select_ = wait.until(EC.visibility_of_element_located((By.XPATH, "//select[contains(@class, 'select-text smaller-text')]")))
selectopt = Select(select_)
selectopt.select_by_value('1cfc3cd0ac77bba30ffac794183100dc220758511a6c943264f8273d90eb54c2')
Upvotes: 1