0

I'm trying to click an "export as csv" button on this webpage using selenium https://monitoringpublic.solaredge.com/solaredge-web/p/site/public?name=Alva%20Court%20E5&locale=en_GB#/dashboard (the button is next to "Power and Energy" title). Once I run the program, the site pops up but the download button is not clicked, resulting on Timeout Exception

However the code works with the following site that I found from another StackOverflow question https://www.rotowire.com/football/injury-report.php (although once I run the program and the site pops up, I have to manually accept the cookies in order for the file to be downloaded but that's another issue).

My question is why does the second link work but the first does not?

Here is the code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

browser = webdriver.Chrome("C:/Path/chromedriver.exe")
url = 'https://monitoringpublic.solaredge.com/solaredge-web/p/site/public? name=Alva%20Court%20E5&locale=en_GB#/dashboard'
browser.get(url)

button = wait(browser, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "is-csv")))
button.click()

browser.close()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
John
  • 410
  • 1
  • 9
  • 21

3 Answers3

1

For Power and Energy selector is #power_energy_panel button[class*=export].
For Comparative Energy is #se-comparative-energy-panel button[class*=export].

url = "https://monitoringpublic.solaredge.com/solaredge-web/p/site/public?name=Alva%20Court%20E5&locale=en_GB#/dashboard"

browser.get(url)
button = WebDriverWait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#power_energy_panel button[class*=export]")))
button.click()
Sers
  • 12,047
  • 2
  • 12
  • 31
1

To invoke click() on the element with tooltip text as Export as CSV you have to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//p[@class='x-panel-header-text' and text()='Power and Energy']//following::button[1]"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

Power_Energy

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you it works. May I ask, is there any reason you didn't choose to just find the button by the ID and click it? Because it seems simpler. – John Aug 17 '19 at 13:48
  • @John Here the idea was to locate the _panel-header-text_ as **Power and Energy** and wrt it find the respective (desired) button and in doing so it seems the _ID_ attribute wasn't required. Hence I dropped using it. – undetected Selenium Aug 17 '19 at 14:31
  • Thank you. Also, do you know if it is possible to get the link of that button? Looking at the "inspect element" code, there isn't any URL. I'm actually looking for a way to download that csv file without opening the web browser because it takes time if I do it for multiple links. – John Aug 30 '19 at 07:38
  • @John That's doable. Can you raise a new question please? – undetected Selenium Aug 30 '19 at 07:46
-1

The class name is incorrect. try with following class name,

button = wait(browser, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "se-button-btn export_csv_btn")))
button.click()
Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18
  • You can't specify more than one class name when using By.CLASS_NAME. It only takes one class name or you have to use a CSS selector. – JeffC Aug 09 '19 at 15:50
  • @JeffC So the ask is to have the same locator work for two different sites? – Sureshmani Kalirajan Aug 09 '19 at 16:06
  • I'm not addressing what OP is asking, you'll have to ask him for clarification there. I'm only talking about the incorrect use of By.CLASS_NAME in your answer. – JeffC Aug 09 '19 at 17:36