Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97756

SOLVED Selenium: Console js code works but not python -> TypeError: document.getElementById(...) null error clicking on element within iframe

$
0
0

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')

Viewing all articles
Browse latest Browse all 97756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>