Selenium XPath error - Element not found

–1 vote

My Selenium Chromedriver script with Python should login to a website and click on a download button which will download a CSV file. On inspecting, details of download button is:

<button id="csv-button" class="block tiny-margin-top" data-args="csv">

and XPath is:


but it says XPath element not found when I run the script. Please find the code below:

click_button = driver.find_element_by_xpath('//*[@id="csv-button"]')
Mar 27, 2018 in Selenium by code_ninja
• 6,280 points

1 answer to this question.

0 votes

The reason for Element not found exception could be because there is a timeout issue. The WbeDriver is getting timedout before your page loads completely.  Try using implicit/ explicit wait statements to overcome this problem.
Add this line of code after the last line in the above code:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='csv-button']"))).click()

Also remember to import this package:

from import expected_conditions as EC
answered Mar 27, 2018 by nsv999
• 5,500 points

if timeout is the problem, then its also an option to just a put a sleep in the code...

After opening the page i usualy put minimum a 2 seconds of sleep like this:


my tests often failed with an "element not found" error, and then i applied this simple method and solved my problem...

Related Questions In Selenium

0 votes
1 answer

Getting error saying element not found in selenium

Hey @Jino, The things I figured out ...READ MORE

answered Dec 20, 2018 in Selenium by Shuvodip
0 votes
1 answer

Xpath element not found

You need to induce WebDriverWait with expected_conditions ...READ MORE

answered Mar 27, 2018 in Selenium by ned_crew
• 1,610 points
0 votes
1 answer

Selenium-Debugging Error: Element is not clickable at point (X,Y)

Another element is covering the element you ...READ MORE

answered Jul 2, 2018 in Selenium by Samarpit
• 5,890 points
+1 vote
2 answers

Python with Selenium issue: “Chrome is being controlled by automated test software”

from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_experimental_option("excludeSwitches",["enable-automation"]) driver ...READ MORE

answered Apr 20, 2020 in Selenium by Manoj
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
0 votes
1 answer

Need to download a file using Selenium

Pretty simple...Find the element or link using ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

How to use Selenium with Python?

Hey Shubham, you can checkout this thread ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,040 points
0 votes
1 answer

Selenium ChromeDriver issue - Want to run it in background, but not as headless browser

This is a flaw with ChromeDriver. Tried ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,500 points