Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用selenium编写测试时,如何查看生成的HTML?_Python_Html_Selenium_Selenium Ide - Fatal编程技术网

Python 使用selenium编写测试时,如何查看生成的HTML?

Python 使用selenium编写测试时,如何查看生成的HTML?,python,html,selenium,selenium-ide,Python,Html,Selenium,Selenium Ide,以python中的以下selenium测试为例: 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_se

以python中的以下selenium测试为例:

 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()
摘自:

结果输出类似于:

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

OK
有没有办法让selenium在执行浏览器操作后输出html

基本上,我使用SeleniumIDEforFirefox在浏览器上记录操作。我想在python上播放它们,得到结果的html,并基于该html采取进一步的行动(例如,第一个selenium测试可能是登录到某个网站并导航到某个地方。根据那里的内容,我想进行第二个测试(即用户仍然登录))。这是否可能使用硒


提前谢谢

听起来你的测试可能最终会相互依赖,这是一个非常糟糕的想法

尽管如此,
page\u source
函数将返回驱动程序正在查看的当前页面的完整HTML:


听起来你的测试可能最终会相互依赖,这是一个非常糟糕的想法

尽管如此,
page\u source
函数将返回驱动程序正在查看的当前页面的完整HTML:


在selenoimRC中有一个
gethtml()
方法,您可以尝试寻找类似的东西,并使用python的IO将其写入文件。在selenoimRC中有一个
gethtml()
方法,您可以尝试寻找类似的东西,并使用python的IO将其写入文件。这正是我想要的。谢谢正是我想要的。谢谢