My Selenium code logs into a website, then reaches a page with a button that exists within an iframe. Inspecting the element in chrome and using the console of the browser, I found the iframe:
iframe = document.getElementById("deputy-app-view1045")
Then I found the element and am able to click it:
iframe.contentWindow.document.getElementById("csv_download").click()
In my python code, I inserted:
browser.execute_script('document.getElementById("deputy-app-view1043").contentWindow.document.getElementById("csv_download").click()')
However, the error is "TypeError: document.getElementById(...) is null".
:(
[SOLUTION] FIGURED IT OUT! Simply had to add a 'return' inside the js script! Thanks everyone! OLD VERSION:
browser.execute_script('document.getElementsByClassName("app-iframe dg-content-box margin-none Report Builder (BETA) ready")[0].contentWindow.document.getElementById("csv_download").href')
FIXED VERSION:
browser.execute_script('return document.getElementsByClassName("app-iframe dg-content-box margin-none Report Builder (BETA) ready")[0].contentWindow.document.getElementById("csv_download").href')