【Python】TypeError: bro_max() missing 1 required positional argument: 'self'

代码编写时

  class Browser(object):
        def bro_max(self):
              #窗口最大化
              self.driver.maximize_window()

调用时

  from selenium import webdriver
  from common.Browser import Browser
  
  
  def set_driver():
      driver = webdriver.Chrome()
      driver.implicitly_wait(10)  
      Browser.bro_max()       # 错误地方
      driver.get("https://www.cnblogs.com/TD1900/")
  
  if __name__ == '__main__':
      set_driver()

原因:没有给类实例化

解决方法:

  from selenium import webdriver
  from common.Browser import Browser


  def set_driver():
      driver = webdriver.Chrome()  
      browser = Browser(driver)   # 增加类实例化
      driver.implicitly_wait(10)
      browser.bro_max()
      driver.get("https://www.cnblogs.com/TD1900/")


  if __name__ == '__main__':
      set_driver()
posted @ 2020-08-04 10:17  心脏鼓点  阅读(620)  评论(0编辑  收藏  举报