Skip to content Skip to sidebar Skip to footer

Selenium For Python: How To Dump Current Page's Html

Using the selenium module, how do I dump the current page's HTML (for debugging purposes)? It doesn't say how to here: http://selenium-python.readthedocs.io/api.html

Solution 1:

You can dump the current page's HTML content using the WebDriver property page_source.

Sample snippet:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://yourfavoriteurl')
if'interested_string'in driver.page_source:
    print('String matched!')

Solution 2:

For debugging purpose to dump the current page's HTML you can invoke the page_source method as :

driver.page_source

Post a Comment for "Selenium For Python: How To Dump Current Page's Html"