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">
      CSV
</button>

and XPath is:

//*[@id="csv-button"]

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"]')
click_button.click()
Mar 27, 2018 in Selenium by code_ninja
• 6,300 points
20,496 views

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 selenium.webdriver.support 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:

Thread.sleep(2000);

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

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 21, 2018 in Selenium by Shuvodip
5,517 views
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
3,406 views
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,910 points
8,936 views
+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
15,895 views
+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 28, 2018 in Selenium by nsv999
• 5,500 points
27,377 views
0 votes
1 answer

Need to download a file using Selenium

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

answered Mar 30, 2018 in Selenium by nsv999
• 5,500 points
3,483 views
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,140 points
1,195 views
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 27, 2018 in Selenium by nsv999
• 5,500 points
8,060 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP