I have a similar question that's being worked, but I made an error and I don't think editing the other question makes sense as it requires a complete rewrite and would make the original question (and answers) nonsensical. Apologies for the confusion.
Using Selenium and Python, I am trying to automate downloading of files from a website. I need to make several clicks on different areas of the page in order to kick off the download process.
In my other question I state that I was able to expose the choices in the dropdown menu, but that is not true. I'm not sure why I thought that. So, I need to expose the menu choices first (then I can figure out how to select them - which my other question addresses).
Here is the HTML for the dropdown. I am trying to do the initial click on this dropdown, to expose the choices available; there are four choices displayed when the dropdown is clicked. The choices are constructed using li class (not shown here but I can add them if it helps).
<div class="SLP-dropdown SLP-dropdown-placement-bottomLeft" data-qa="SLP-dropdown" style="left: 429px; top: 436px; width: 117px;">
<ul class="SLP-dropdown-menu SLP-dropdown-menu-root SLP-dropdown-menu-vertical" role-“menu" tabindex="0">
Here is my code. There are two steps here; the first is to check a checkbox which indicates that I want all displayed documents included in the download (this step works fine) and the second is to display the dropdown menu.
import selenium
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://sample.url")
#this is the long wait to allow time to log in
driver.implicitly_wait(50)
#this selects the checkbox to choose all listed documents. This works correctly.
driver.find_element(By.ID, "SLP-input").click()
#wait for menu to be ready
driver.implicitly_wait(5)
#this is the attempt to display the choices in the dropdown menu. This click is what is not working, even though the dropdown is ready to be clicked. The choices displayed in this dropdown will allow download the documents selected by the checkbox above.
driver.find_element(By.XPATH, "//ul[@class='SLP-dropdown-menu']").click()
Here is the error message:
---------------------------------------------------------------------------
NoSuchElementException Traceback (most recent call last)
Cell In[2], line 26
23 driver.implicitly_wait(5)
25 #this is the attempt to display the choices in the Download menu. This click is what is not working, even though the dropdown is ready to be clicked
---> 26 driver.find_element(By.XPATH, "//ul[@class='SLP-dropdown-menu']").click()
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py:926, in WebDriver.find_element(self, by, value)
923 raise NoSuchElementException(f"Cannot locate relative element with: {by.root}")
924 return elements[0]
--> 926 return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py:458, in WebDriver.execute(self, driver_command, params)
455 response = cast(RemoteConnection, self.command_executor).execute(driver_command, params)
457 if response:
--> 458 self.error_handler.check_response(response)
459 response["value"] = self._unwrap_value(response.get("value", None))
460 return response
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:232, in ErrorHandler.check_response(self, response)
230 alert_text = value["alert"].get("text")
231 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 232 raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//ul[@class='SLP-dropdown-menu']"}
(Session info: chrome=143.0.7499.41); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#nosuchelementexception
Stacktrace:
Symbols not available. Dumping unresolved backtrace:
0x7ff74a928255
0x7ff74a9282b0
0x7ff74a70165d
0x7ff74a759a33
0x7ff74a759d3c
0x7ff74a7adf67
0x7ff74a7aac97
0x7ff74a74ac29
0x7ff74a74ba93
0x7ff74ac3fff0
0x7ff74ac3a930
0x7ff74ac59096
0x7ff74a945754
0x7ff74a94e6fc
0x7ff74a931974
0x7ff74a931b25
0x7ff74a917852
0x7ff96614e8d7
0x7ff966b4c53c
driver.implicitly_wait()doesn't do what you think it does. It's a one time setting of the default time out, not an actual wait. The Selenium lead and others have stated for years that implicit waits should not be used... instead useWebDriverWaitwhenever a wait is needed.