-1

Hi I want to download the data from Link where I want to download the data from region 'SA'. I have tried following code, where after selecting 'SA' tab I want to click on download arrow above '30 Min' tab.

chromedriver = "/usr/lib/chromium-browser/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get('https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/Data-dashboard#price-demand')
time.sleep(5)
driver.find_element_by_xpath("//*[@class='au-target btn btn-default btn-lg active' and text()='SA']").click()
button = driver.find_element_by_xpath("//button[@class='btn btn-default au-target' and click.trigger='clickDownload($event)']")
button.click()

However it throws error

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class='au-target btn btn-default btn-lg active' and text()='SA']"}

You can get the xpath by visiting Link.

Thank you in advance.

Community
  • 1
  • 1
Nikhil Mangire
  • 397
  • 5
  • 13
  • you are having the wrong xpath; SA button xpath: "/html/body/div/compose/div/compose[2]/div/span[1]/compose/button[4]" and download xpath: "/html/body/div/compose/div/compose[1]/div[1]/div/div/button[1]" – Carlo 1585 Oct 30 '18 at 12:57
  • Possible duplicate of [Select iframe using Python + Selenium](https://stackoverflow.com/questions/7534622/select-iframe-using-python-selenium) – JeffC Oct 30 '18 at 14:06

2 Answers2

1

Once you access the url https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/Data-dashboard#price-demand to download the required data you need to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element with text as SA to be clickable.
  • Induce WebDriverWait again for the desired element to be clickable.
  • You can use the following solution:
  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument("start-maximized")
    options.add_argument("disable-infobars")
    options.add_argument("--disable-extensions")
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get('https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/Data-dashboard#price-demand')
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='iframe-dashboard-MTO' and@src='/aemo/apps/visualisations/elec-nem-priceanddemand.html']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='au-target btn btn-default btn-lg' and contains(.,'SA')]"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='btn-group']//following::button[1]/i[@class='icon-download']"))).click()
    
  • Browser Snapshot:

aemo

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Both buttons are located inside an iframe, so you should switch to that frame before clicking buttons:

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

driver.switch_to.frame(driver.find_element_by_class_name('iframe-dashboard-MTO'))
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='SA']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'icon-download'))).click()
Andersson
  • 51,635
  • 17
  • 77
  • 129