I ran into this problem, I was trying to automate a process in Python that required filling out a web page and selecting values from a dropdown menu. However, I'm facing an issue where the page is not updating even when the dropdown value is selected.
This is the code to select this specific element:
import os
import time
import pandas as pd
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options=Options()
#options.page_load_strategy='none'
options.add_experimental_option("detach", True)
options.add_argument('User_profile on mac')
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
file=r'Example.xlsx'
webpage=r'url'
df_file=pd.read_excel(file)
browser.maximize_window()
for i,row in df_file.iterrows():
time.sleep(3)
browser.get(webpage)
time.sleep(3)
WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.XPATH,'/htm
l/body/div[1]'))).click()
cat2=browser.find_element(By.XPATH,'/html/body/span[1]')
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID,'s2id_autogen1'))).click() #looks for the first dropdown
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="select2-result-label-21"]'))).click() #finds the correct option
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, 's2id_autogen3'))).click() #finds the second dropdown
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="select2-results-4"]/li[11]'))).click() #clicks on load more
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="select2-result-label-34"]'))).click() #click on correct option
problematic_dropdown=Select(browser.find_element(By.XPATH,'//*[@id="pageAside"]/div[2]/div/dep-gud-request-ors/dep-request-ors/es-view-form/form/dep-control-request-recipients/dep-control-request-recipient/div[2]/div/fieldset/dep-control-request-recipient-household/es-view-select2[1]/div/div[1]/div/select'))
browser.implicitly_wait(3)
problematic_dropdown.select_by_value('1') #once this value is selected, the page does not load
I've tried selecting different values and then selecting the desired value again; I've tried using implicit and explicit waits and making the code sleep for 20 seconds. Unfortunately, nothing works. When I manually log into the website and select a value, the page updates normally.
I highly recommend using a better xpath selector if you can, but for what you want to do, just click directly on the
optionelement, no need to expand the select box first p>