Selenium XPath error:- Element not found

0 votes

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,220 points
2,552 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,070 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 20, 2018 in Selenium by Shuvodip
265 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,620 points
181 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,130 points
2,131 views
0 votes
1 answer
+1 vote
1 answer
+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,070 points
5,839 views
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,070 points
372 views
0 votes
2 answers

How to use Selenium with Python?

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

answered 50 minutes ago in Selenium by Abha
• 20,280 points
148 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 26, 2018 in Selenium by nsv999
• 5,070 points
872 views