I’m trying to get an href link to download an XBRL file for a 10-Q financial report from an SEC webpage. Selenium is able to open the webpage but then it must click on the menu button in the top left to expand the menu to get to the ‘Save XBRL Zip File’ button but fails to do so. When I run my code, the TimeoutException is raised, no matter how much waiting time is specified. The XPATH is the one selected by the element selector when I inspect the html of the opened webpage. I am very new to programming. I found similar questions but the answers did not solve my issue. Any help is greatly appreciated!
This code is a subset of my script. Selenium worked fine up to this point including clicking other buttons. In the subet, below, if there are no issues, the webpage should open and the menu should be expanded. You can left click on the menu to see the expanded form. I tried adding logging and try and except statements to debug. I have also tried all other XPATHs that seem to point to the menu button. I tried expanding the menu button using javascript with <driver.execute_script(“arguments[0].click();”, menu_button)> Causes I can think of are: a text popup for the button appears when I hover over it and might be interfering with Selenium; javascript is interfering. Since I can see the href link for the XBRL file when I inspect the webpage opened by Selenium, I tried using Beautifulsoup to get the href to no avail.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementNotInteractableException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.common.exceptions import StaleElementReferenceException
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import TimeoutException
# Initialize the Edge WebDriver (I have not tried Chrome because I was having issues with the
# driver)
driver = webdriver.Edge()
# Open the webpage
url = r'https://www.sec.gov/ix?doc=/Archives/edgar/data/0001652044/000165204424000079/goog-20240630.htm'
driver.get(url)
# Wait for the page to fully load
wait = WebDriverWait(driver, 10)
try:
# Get the menu element
menu_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='menu-dropdown-link']/span[2]")))
# Logging for debugging
print(f"Menu button displayed: {menu_button.is_displayed()}")
print(f"Menu button enabled: {menu_button.is_enabled()}")
# Click on the menu to expand it
menu_button.click()
# Print exceptions for debugging
except NoSuchElementException as e:
print("Element not found: ", e)
except ElementNotInteractableException as e:
print("Element not interactable: ", e)
except ElementClickInterceptedException as e:
print("Element click intercepted: ", e)
except StaleElementReferenceException as e:
print("Stale element reference: ", e)
except ElementNotVisibleException as e:
print("Element not visible: ", e)
except TimeoutException as e:
print("Timeout: ", e)
The output, which I can’t understand and Copilot says is not very informative, is:
Timeout: Message:
Stacktrace:
GetHandleVerifier [0x00007FF729758162+13538]
Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF7296E1E19+595513]
(No symbol) [0x00007FF7294FE6CF]
(No symbol) [0x00007FF729542960]
(No symbol) [0x00007FF729542A1F]
(No symbol) [0x00007FF72957D627]
(No symbol) [0x00007FF72956203F]
(No symbol) [0x00007FF729538147]
(No symbol) [0x00007FF72957B1EE]
(No symbol) [0x00007FF729561C63]
(No symbol) [0x00007FF72953766E]
(No symbol) [0x00007FF72953683C]
(No symbol) [0x00007FF729537221]
Microsoft::Applications::Events::EventProperty::to_string [0x00007FF729919704+1099860]
Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF72965D8FC+53532]
Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF729650E25+1605]
Microsoft::Applications::Events::EventProperty::to_string [0x00007FF729918695+1095653]
Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF7296EC991+27777]
Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF7296E6D14+4100]
Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF7296E6E4B+4411]
Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF7296DCFD0+575472]
BaseThreadInitThunk [0x00007FFF7C437374+20]
RtlUserThreadStart [0x00007FFF7D3BCC91+33]
catman1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.