killajoule
killajoule

Reputation: 3832

When writing tests with selenium how can you view the resulting HTML?

Take for example the following selenium test in python:

 import unittest
 from selenium import webdriver
 from selenium.webdriver.common.keys import Keys

 class PythonOrgSearch(unittest.TestCase):

     def setUp(self):
         self.driver = webdriver.Firefox()

     def test_search_in_python_org(self):
         driver = self.driver
         driver.get("http://www.python.org")
         self.assertIn("Python", driver.title)
         elem = driver.find_element_by_name("q")
         elem.send_keys("selenium")
         elem.send_keys(Keys.RETURN)
         self.assertIn("Google", driver.title)

     def tearDown(self):
         self.driver.close()

 if __name__ == "__main__":
     unittest.main()

Taken from: http://selenium-python.readthedocs.org/en/latest/getting-started.html#id2

The resulting output is something like:

----------------------------------------------------------------------
Ran 1 test in 15.566s

OK

Is there any way to get selenium to output the html after it has executed its browser actions?

Basically, I am using Selenium IDE for Firefox to record actions on the browser. I want to play them back on python, get the resulting html, and based on that html take further action (e.g. the 1st selenium test might be to log on to a website and navigate somewhere. Based on what is there I want to conduct a second test (w. the user still logged on)). Is this possible using selenium?

Thanks in Advance!

Upvotes: 1

Views: 920

Answers (1)

Arran
Arran

Reputation: 25066

It sounds as though your tests might end up being dependant on each other, which is a very very bad idea.

Nonetheless, the page_source function will return the full HTML of the current page the driver is looking at:

https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/remote/webdriver.py#429

Upvotes: 1

Related Questions