I have below html code, all I want to click on the dropdown and select the first value.How can I achieve this.I am having issues when selecting the values from dropdown but was able to click the dropdown
<div id= "location-select-list" class="mb-list" role="role0">
<mb-option id='1' class='classname' role='rolename' data-auto-id="dt1" aria-disabled="False" 1 </mb-option>
<mb-option id='2' class='classname' role='rolename' data-auto-id="dt2"aria-disabled="False" 2 </mb-option>
I have tried this but not working.
#click on the dropdown--working
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH,
xpath_0))).click()
#selecting 1st value from the dropdown value list--not working
xpath = "//div[@id='location-select-list']//mb-option[@data-auto-id='dt1']"
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH,
xpath))).click()
CodePudding user response:
<div id= "location-select-list" class="mb-list" role="role0">
<mb-option id='1' class='classname' role='rolename' data-auto-id="dt1" aria-disabled="False" 1 </mb-option>
<mb-option id='2' class='classname' role='rolename' data-auto-id="dt2"aria-disabled="False" 2 </mb-option>
Try this
#click on the dropdown--working
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH,
xpath_0))).click()
#my code
elem_list = driver.find_elements_by_class_name('classname')
elem_list[0].click()
Or
elem_list = driver.find_elements(By.XPATH, "//mb-option[contains(@class, 'classname')]"):
elem[0].click()