Python + WebDriver — No browser launched while using unittest module

后端 未结 3 2223
孤街浪徒
孤街浪徒 2021-01-24 20:51

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:



        
3条回答
  •  忘了有多久
    2021-01-24 21:27

    I'm not sure as I haven't tested it but I suspect the browser is still opened from the first code. So what I suggest here is to use driver.close() to terminate the process properly once you get out of script.

    import unittest
    from selenium import webdriver
    driver = webdriver.Chrome('D:\chromedriver\chromedriver.exe')
    driver.get("site URL")
    driver.close()  # Must be there
    

    Similarly, you can make modification in the test script to put self.driver.close() in the tearDown method.

提交回复
热议问题