0

I need, click a dropdown menü element. But I'm new Selenium Webdriver and I cant find anything

<div class="sort-fltr-cntnr"><select>
<option value="SCORE">Önerilen</option>
<option value="PRICE_BY_ASC">En Düşük Fiyat</option>
<option value="PRICE_BY_DESC">En Yüksek Fiyat</option>
<option value="MOST_RECENT">En Yeniler</option>
<option value="BEST_SELLER">Çok Satanlar</option> ....

Its my code:

dropdown = self.driver.find_element(By.CSS_SELECTOR, "select")
element=dropdown.find_element(By.XPATH, "//option[. = 'Önerilen']")
self.driver.execute_script("arguments[0].click();", element)
time.sleep()
dropdown.find_element(By.XPATH, "//option[. = 'En Düşük Fiyat']").click()

An given a error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //option[. = 'Önerilen']
Sdeveci
  • 11
  • 2
  • 3
  • Does this answer your question? [How to select a drop-down menu value with Selenium using Python?](https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python) – Alex Montano Oct 16 '21 at 20:56

1 Answers1

1
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

select = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "sort-fltr-cntnr"))))
select.select_by_value('SCORE')

Simply wait for the class name with sort to be clickable and then select the score value.

Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32