CodexBloom - Programming Q&A Platform

Selenium WebDriver scenarios to click on dropdown options in a jQuery UI autocomplete widget on Chrome 120

👀 Views: 344 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-17
selenium webdriver jquery ui autocomplete Python

I'm updating my dependencies and I've been working on this all day and I'm having trouble with Selenium WebDriver when trying to interact with a jQuery UI autocomplete dropdown. After inputting text into the autocomplete field, the dropdown appears, but when I attempt to click on any of the options, nothing happens. I am using Chrome 120 and the latest version of ChromeDriver. My code looks like this: ```python from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys import time # Initialize WebDriver driver = webdriver.Chrome() try: driver.get('http://example.com') # Replace with your URL search_box = driver.find_element(By.ID, 'autocomplete-input') # Adjust ID as necessary search_box.send_keys('test') time.sleep(2) # Wait for dropdown to appear # Locate the dropdown option option = driver.find_element(By.XPATH, '//ul[@id="ui-id-1"]/li[1]') # Adjust XPath as necessary option.click() # Attempt to click on the option except Exception as e: print(f'behavior: {e}') finally: driver.quit() ``` I've tried adding explicit waits using WebDriverWait to ensure the option is clickable, like this: ```python from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Wait for the option to be clickable wait = WebDriverWait(driver, 10) option = wait.until(EC.element_to_be_clickable((By.XPATH, '//ul[@id="ui-id-1"]/li[1]'))) option.click() ``` Despite this, the click action still does not select the option. I also verified that the element is present and visible before clicking. I get no errors, but the expected result is not occurring. Is there something specific to jQuery UI widgets that I might be missing? Any insights or help would be greatly appreciated! This is part of a larger API I'm building. I recently upgraded to Python stable. The stack includes Python and several other technologies. What am I doing wrong?