0

i am trying to go to a certain website with selenium and click a button to load data then download csv file, I have tried using id,Xpath, class by I am still getting an error: any hint will be helpful.

here is my code below:

from selenium import webdriver

driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://eatradingacademy.com/software/forex-historical-data/')
driver.find_element_by_id("webpushr-deny-button").click()
driver.find_element_by_class_name('text-center')

here is the error i am getting:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".text-center"}

(Session info: chrome=91.0.4472.124)

  • I see no element matching `webpushr-deny-button` string there. – Prophet Jul 05 '21 at 10:01
  • The webpushr-deny button is for denying the pop up message that is asking to receive notifications on latest updates, The error occurs when i run the last line. – Khutso Mphelo Jul 05 '21 at 10:05
  • can you clarify what do you mean by this `driver.find_element_by_class_name('text-center')` ? what element are you trying to access using this class name? is it `Load Data` button? – Rohit Babu Jul 05 '21 at 10:19
  • If you go on the website there is button called “load data” so when I am inspecting it I get the class to be “text-center” so untimely I would like to click that button – Khutso Mphelo Jul 05 '21 at 10:22
  • 1
    You would like to click it and from the resulting table, download the data you want but the loading isn't happening. right? From my inspection, iframe might be the reason for your error. – Rohit Babu Jul 05 '21 at 10:41

1 Answers1

0

I think the error is due to the button you're trying to click is wrapped inside an iframe.

Typically, you will have switch to an iframe in order to access elements inside it.

Try

driver.switch_to.frame(driver.find_element_by_id('data-app-frame'))

This will switch the webdriver to the iframe having id data-app-frame

Now try clicking your button using driver.find_element_by_id('btn-load-data')

This should work.

Here I am accessing the same button you tried to access in the question. In the question you are trying to access parent div instead of the button element itself. It is recommended to access the actual element instead of it's parent

You can learn more about frame switching here

Rohit Babu
  • 380
  • 3
  • 14