Samer Adnan
Samer Adnan

Reputation: 59

Autofill dropdown input python using selenium

I want to autofill dropdown input

ex:

dropdown List

.css:

<input class="ui-dropdown-filter ui-inputtext ui-widget ui-state-default ui-corner-all" autocomplete="off" type="text">

</div><div class="ui-dropdown-items-wrapper" style="max-height: 200px;"><ul class="ui-dropdown-items ui-dropdown-list ui-widget-content ui-widget ui-corner-all ui-helper-reset">

<li class="ng-tns-c1-0 ui-dropdown-item ui-corner-all ng-star-inserted" style=""><!----><span class="ng-tns-c1-0 ng-star-inserted">Alabma</span><!----></li>

<li class="ng-tns-c1-0 ui-dropdown-item ui-corner-all ng-star-inserted" style=""><!----><span class="ng-tns-c1-0 ng-star-inserted">Alaska</span><!----></li>

</ul>

I tried:

 elementt = driver.find_element_by_css_selector(".ui-dropdown")
 driver.execute_script("arguments[0].click();", elementt)

 select = Select(driver.find_element_by_class_name('input.ui-dropdown-filter.ui-inputtext.ui-widget.ui-state-default.ui-cornee-all'))

 select.select_by_visible_text("Alaska")

But Nothing happen, any kind of help please?

Upvotes: 0

Views: 199

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

If you are able to click on drop down using :

elementt = driver.find_element_by_css_selector(".ui-dropdown")
driver.execute_script("arguments[0].click();", elementt)

then you should try :

driver.find_element_by_xpath("//span[text()='Alabma']/..").click() 

to click on option, also you can change the text as per requirement.

Upvotes: 1

Related Questions