I am trying to select a value from a dropdown menu. I tried a lot of solutions found here but nothing work, sometimes I have the error can\'t scroll to view.
Code trials
To select an option e.g. Automobiles from a dropdown menu of non tag you can use the following solution:
Code Block:
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
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://dzairannonces.com/posts/create')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.select2-selection__rendered#select2-parentId-container"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='select2-results']/ul//li[@class='select2-results__option' and contains(., 'Automobiles')]"))).click()
Browser Snapshot: