I try to handle a dropdown menu to click on the 'Popular' option within this website using selenium, but no one example which I found doesn't suit for that.
<select class="select__select--2gOcq explorerSortMenu__explorerSortPopoutMenu--3pMwT">
<option value="desc__" selected="">Highest User Rating</option><option
value="desc__discount_percent">Discount</option><option value="asc__price">Price: Low to High</option><option value="desc__price">Price: High to Low</option><option value="desc__ratings_count">Popular</option></select>
Have used CSS, Xpath and Select, but the result is the same: No such element. Bellow you can see attempts and outputs.
Any ideas what I do wrong?
CSS Selector
browser.find_element_by_css_selector('.select__select--2gOcq.explorerSortMenu__explorerSortPopoutMenu--3pMwT')
Message: no such element: Unable to locate element: {"method":"css selector","selector":".select__select--2gOcq.explorerSortMenu__explorerSortPopoutMenu--3pMwT"}
Xpath
browser.find_element_by_xpath('//input[starts-with(@class,"select__select--2gOcq")]')
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[starts-with(@class,"select__select--2gOcq")]"}
Select
Select(browser.find_element_by_xpath("//*[@class='select__select--2gOcq explorerSortMenu__explorerSortPopoutMenu--3pMwT']"))
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class='select__select--2gOcq explorerSortMenu__explorerSortPopoutMenu--3pMwT']"}
UPDATE:
After executed the code bellow the element was successfully located but, I have caught the TimeoutException
.
driver = webdriver.Chrome()
driver.get(URL)
try:
select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[starts-with(@class, 'select__select--') and contains(@class, 'explorerSortMenu__explorerSortPopoutMenu--')]"))))
select.select_by_visible_text('Popular')
select.click()
finally:
driver.quit()