I'm running Selenium to download a sample PdF file and open it in Chrome but for some reason, I can't manage to get Selenium to click on the first result in the downloads section.
The XPath has been specified but it just won't click on the element, the process is just aborted due to a timeout error (below). Please, does anyone have any ideas of what I am doing wrong?
======================================================================
ERROR: testSearch (__main__.InitialSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/Josh/PycharmProjects/ideqcomps/test.py", line 33, in testSearch
lambda driver: driver.find_elements_by_xpath(downloaded_file_XPath))
File "/Users/Josh/Library/Python/3.6/lib/python/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
----------------------------------------------------------------------
Ran 1 test in 24.415s
FAILED (errors=1)
Process finished with exit code 1
Here is the code I'm running:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import unittest
class InitialSearch(unittest.TestCase):
def setUp(self):
options = webdriver.ChromeOptions()
self.driver = webdriver.Chrome(chrome_options=options)
self.driver.get("https://wetransfer.com/downloads/5451e039a782938826861676664ae91a20171227191356/a45960")
def testSearch(self):
driver = self.driver
download_button_xpath = '//*[@id="file-link"]'
agree_xpath = '//*[@id="5451e039a782938826861676664ae91a20171227191356"]/div/div[2]/button'
downloaded_file_xpath = '//*[@id="downloads-list"]/downloads-item[1]'
# Click on agree to terms button
agree_element = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_xpath(agree_xpath))
agree_element.click()
# Click on download button
download_button_element = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_xpath(download_button_xpath))
download_button_element.click()
# Go to downloads
self.driver.get("chrome://downloads/")
# Click on first item in downloads
open_pdf_element = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_xpath(downloaded_file_xpath))
open_pdf_element.click()
if __name__ == '__main__':
unittest.main()
downloaded_filelink is within a shadow-root i.e shadowDOM you need to useJavascriptExecutor