How to get javascript results using selenium?

I have the following code:

from selenium import selenium

selenium = selenium("localhost", 4444, "*chrome", "http://some_site.com/")
selenium.start()

sel = selenium
sel.open("/")
sel.type("ctl00_ContentPlaceHolder1_SuburbTownTextBox", "Adelaide,SA,5000")
sel.click("ctl00_ContentPlaceHolder1_SearchImageButton")

#text = sel.get_body_text()
text = sel.get_html_source()

print(text)

Clicking executes a javascript file, which then displays the results on the same page. Obviously, print(text)only the source of orignal html will print. How can I get javascript results?

+3
source share
1 answer

try this to get the content of the html element with id = your-id:

sel.get_eval("this.browserbot.getCurrentWindow().document.getElementById('your-id').innerHTML"
+4
source

Source: https://habr.com/ru/post/1737516/


All Articles