0

In my Selenium test I need simply save web page content after all Ajax objects has been loaded. I have found answers how to wait for Ajax loading, however there is no working solution for saving whole page with Ajax content. Here is source example:

with contextlib.closing(webdriver.Chrome()) as driver:
    driver.get(url)  # Load page

    # Just as an example, wait manually until all Ajax objects are loaded.
    raw_input("Done?")

    # Save whole page
    text = driver.page_source
    # text contains original page data, no Ajax elements

I assume I need to tell web driver to check with the browser and update page_source property. Is there API for that? How do you save page containing Ajax objects?

Edit: Thanks for the reply! After re-testing with sample Ajax site I've figured that above code works. The problem was that the site uses frames, therefore I need to switch to a proper one. Here is another post answering that: What does #document mean?

Community
  • 1
  • 1
Alex_M
  • 43
  • 5

2 Answers2

0

page_source should return the HTML of page as now, and include any HTML generated post page load by AJAX. You should not have to call different methods to get the AJAX generated content.

Is there a public link to the site we can see?

Robbie Wareham
  • 3,380
  • 1
  • 20
  • 38
-1

After opening the page then refresh the page and then get the source code

driver.refresh()

text = driver.page_source

Imran Rafiq
  • 308
  • 2
  • 5
  • 15