PythonNoobard
PythonNoobard

Reputation: 1

Facing NoSuchElementException and Timeoutexception while using Chromedriver to download some excel files

I am facing NoSuchElementException while using XPATH and Timeoutexception while using execute script while downloading some excel files via chromedriver.

From the website I am trying to click on Key Fund Documents but it is not able to find it either directly by find_element xpath or through execute script

Code: #driverlocation & chromeoptions has been defined before


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

website = "https://www.northerntrust.com/united-kingdom/what-we-do/investment-management/pooled-funds"
driver = webdriver.Chrome(driver_location,options=chrome_options) 
enable_download_headless(driver,filepath_data)
driver.get (website)
time.sleep(15)
driver.find_element(By.ID,'truste-consent-button').click() 
time.sleep(3)
driver.find_element(By.XPATH,"/html/body/div[1]/div[3]/div/div[2]/div/div[3]/div/div[1]/div/div/div/noindex/div/div/ul/li[3]/div").click()
driver.execute_script("arguments[0].click();",WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[1]/div[3]/div/div[2]/div/div[3]/div/div[1]/div/div/div/noindex/div/div/ul/li[3]/div"))))

Either of the last 2 ways of clicking do not work.

Was expecting the Key Fund Documents to be clicked but facing an exception there.

enter image description here

Upvotes: 0

Views: 58

Answers (1)

PythonNoobard
PythonNoobard

Reputation: 1

Solved this myself. The issue was that the XPATH is contained within an iframe so it was not able to find the element as the XPATH becomes different in an iframe.

Solution is to first switch to the iframe and then use find element using XPATH.

iframe = driver.find_element(By.XPATH, "//iframe[@id='ntframe']")
driver.switch_to.frame(iframe)

Upvotes: 0

Related Questions