Xpath element not found

0 votes

I was using Selenium,Python and Chromedriver script which will login to a website and use click on a download button which will download a CSV file.

Check the inspect details of download button below:

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

XPath is:

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

but it shows an error that XPath element not found when I execute the script. Below is the code:

click_button = driver.find_element_by_xpath('//*[@id="csv-button"]')
click_button.click()
Mar 27, 2018 in Selenium by ffdfd
• 5,550 points
3,483 views

1 answer to this question.

0 votes

You need to induce WebDriverWait with expected_conditions clause set to element_to_be_clickable as follows:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# other code    
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='csv-button']"))).click()

You can also use:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# other code    
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='block tiny-margin-top' and @id='csv-button']"))).click()

answered Mar 27, 2018 by ned_crew
• 1,610 points

Related Questions In Selenium

–1 vote
1 answer

Selenium XPath error:- Element not found

The reason for Element not found exception ...READ MORE

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

Which exception is raised when an element is not found in an HTML DOM using XPath

Hey, A stale element reference exception is thrown in one of two cases If ...READ MORE

answered Jul 30, 2020 in Selenium by Sirajul
• 59,230 points
10,673 views
0 votes
1 answer

Not able to find element with Xpath

You are using wrong xpath expression. This ...READ MORE

answered Jul 4, 2018 in Selenium by Samarpit
• 5,910 points
4,886 views
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,550 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,804 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,208 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,286 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,914 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