I'm trying to click a button to automatically export a csv file from this site. I've tried finding the element by button name and by Xpath, but the "NoSuchElement" Exception is raised. I've tried variations of WebdriverWait and time.sleep to ensure the button loads, and used the xPath finder extension to get the right xPath.
Code is as follows:
#import Packages
import selenium
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
#set URL, Get it, and wait
driver = webdriver.Chrome()
driver.get('https://www.egle.state.mi.us/RIDE/inventory-of-facilities/facilities')
WebDriverWait(driver,11)
#Set and Click button
button = driver.find_element(by=By.XPATH, value='//*[@id="maincontent"]/div/inventory-of-facilities/som-page-section/div/div[2]/div[2]/facilities-table/som-page-section/div/div[2]/div[2]/som-table/div/div/div[1]/div[2]/div[2]/button')
button.click()
The button I'm trying to access is shown in image below:
Before posting I've referenced the following Questions:
- Clicking a button with Selenium button
- How to press/click the button using Selenium if the button does not have the Id?
- AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
*new to Selenium and not well versed in HTML. Any insight is much appreciated.