• <bdo id='sKY2r'></bdo><ul id='sKY2r'></ul>

      <tfoot id='sKY2r'></tfoot>
    1. <i id='sKY2r'><tr id='sKY2r'><dt id='sKY2r'><q id='sKY2r'><span id='sKY2r'><b id='sKY2r'><form id='sKY2r'><ins id='sKY2r'></ins><ul id='sKY2r'></ul><sub id='sKY2r'></sub></form><legend id='sKY2r'></legend><bdo id='sKY2r'><pre id='sKY2r'><center id='sKY2r'></center></pre></bdo></b><th id='sKY2r'></th></span></q></dt></tr></i><div id='sKY2r'><tfoot id='sKY2r'></tfoot><dl id='sKY2r'><fieldset id='sKY2r'></fieldset></dl></div>
    2. <legend id='sKY2r'><style id='sKY2r'><dir id='sKY2r'><q id='sKY2r'></q></dir></style></legend>

      <small id='sKY2r'></small><noframes id='sKY2r'>

      Python + WebDriver -- 使用 unittest 模块时没有启动浏览器

      时间:2023-07-05
      <legend id='fIk2m'><style id='fIk2m'><dir id='fIk2m'><q id='fIk2m'></q></dir></style></legend>
      • <bdo id='fIk2m'></bdo><ul id='fIk2m'></ul>

        <small id='fIk2m'></small><noframes id='fIk2m'>

          <i id='fIk2m'><tr id='fIk2m'><dt id='fIk2m'><q id='fIk2m'><span id='fIk2m'><b id='fIk2m'><form id='fIk2m'><ins id='fIk2m'></ins><ul id='fIk2m'></ul><sub id='fIk2m'></sub></form><legend id='fIk2m'></legend><bdo id='fIk2m'><pre id='fIk2m'><center id='fIk2m'></center></pre></bdo></b><th id='fIk2m'></th></span></q></dt></tr></i><div id='fIk2m'><tfoot id='fIk2m'></tfoot><dl id='fIk2m'><fieldset id='fIk2m'></fieldset></dl></div>
            <tbody id='fIk2m'></tbody>
          1. <tfoot id='fIk2m'></tfoot>

                本文介绍了Python + WebDriver -- 使用 unittest 模块时没有启动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                你能帮我做下一个吗?我发现了问题,但无法解决.当我使用下一个代码时,浏览器已经启动并且测试通过了:

                Could you please help me with the next. I found out the issue and could not resolve it. When I am using next code, the browser has started and the test has passed:

                import unittest
                from selenium import webdriver
                driver = webdriver.Chrome('D:chromedriverchromedriver.exe')
                driver.get("site URL")
                

                但与类和方法相同,返回消息:进程以退出代码 0 完成":

                BUT same with class and methods return message: "Process finished with exit code 0":

                import unittest
                from selenium import webdriver
                class GlossaryPage(unittest.TestCase):
                    def setUp(self):
                        self.driver = webdriver.Chrome(executable_path='D:chromedriverchromedriver.exe')
                        self.driver.maximize_window()
                        self.driver.implicitly_wait(10)
                    def NoLorem(self):
                        driver = self.driver
                        driver.get("site URL")
                    def tearDown(self):
                        unittest.quit()
                

                如何使用第二种情况(使用方法和类)打开浏览器?

                How can I get the browser opened using 2nd case (with methods and class)?

                非常感谢您的帮助.

                推荐答案

                在使用 Selenium 处理 Python 的 unittest 模块时,您必须考虑以下几个事实:

                While working through Python's unittest module with Selenium you have to consider a few facts as follows :

                • 当您传递 Key executable_path 时,通过单引号和原始 r 开关提供 Value.
                • 在定义 @Tests 时,测试以 test 开头的名称,例如def test_NoLorem(self):
                • 当您调用 get() 时,请确保您传递的是有效的 url,例如http://www.python.org
                • 当您在 def tearDown(self) 中调用 quit() 方法时: 通过 WebDriver 实例作为 调用该方法self.driver.quit().
                • 如果您使用 unittest 模块,则必须通过 if __name__ == "__main__":
                • 调用 Tests
                • 这是您自己的代码,并进行了必要的小修改:

                • While you pass the Key executable_path provide the Value through single quotes along with the raw r switch.
                • While you define the @Tests name the tests starting with test e.g. def test_NoLorem(self):
                • While you invoke get() ensure you are passing a valid url e.g. http://www.python.org
                • While you invoke the quit() method within def tearDown(self): invoke the method through the WebDriver instance as self.driver.quit().
                • If you are using unittest module you have to call the Tests through if __name__ == "__main__":
                • Here is your own code with the required minor modifications :

                import unittest
                from selenium import webdriver
                
                class GlossaryPage(unittest.TestCase):
                
                    def setUp(self):
                        self.driver = webdriver.Chrome(executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                        self.driver.maximize_window()
                        self.driver.implicitly_wait(10)
                    def test_NoLorem(self):
                        driver = self.driver
                        driver.get("http://www.python.org")
                    def tearDown(self):
                        self.driver.quit()
                
                if __name__ == "__main__":
                    unittest.main()
                

                这篇关于Python + WebDriver -- 使用 unittest 模块时没有启动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Selenium Threads:如何使用代理运行多线程浏览器(python) 下一篇:显式关闭文件重要吗?

                相关文章

                  <small id='Mf0DP'></small><noframes id='Mf0DP'>

                  <tfoot id='Mf0DP'></tfoot>

                1. <i id='Mf0DP'><tr id='Mf0DP'><dt id='Mf0DP'><q id='Mf0DP'><span id='Mf0DP'><b id='Mf0DP'><form id='Mf0DP'><ins id='Mf0DP'></ins><ul id='Mf0DP'></ul><sub id='Mf0DP'></sub></form><legend id='Mf0DP'></legend><bdo id='Mf0DP'><pre id='Mf0DP'><center id='Mf0DP'></center></pre></bdo></b><th id='Mf0DP'></th></span></q></dt></tr></i><div id='Mf0DP'><tfoot id='Mf0DP'></tfoot><dl id='Mf0DP'><fieldset id='Mf0DP'></fieldset></dl></div>
                  <legend id='Mf0DP'><style id='Mf0DP'><dir id='Mf0DP'><q id='Mf0DP'></q></dir></style></legend>

                      <bdo id='Mf0DP'></bdo><ul id='Mf0DP'></ul>