测试积点老人 发表于 2022-2-7 14:53:43

Selenium关于invalid session id错误

请问一下,我使用Selenium跟Python做网页自动化但是随着几个帐号登入后常会遇到session id invalid的问题导致程序停止
我在执行中已经使用try except去handle所有的错误了但是还是无法解决这个问题标识错误程序码片段try:
            time.sleep(5)

            # Geetest Image
            self.waitGeetest.until(EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/div/div/div/div')))
      
      except TimeoutException:
            print('Geetest验证视窗等待超时,验证失败重新启动')
            self.browser.close()
            self.login()
      except NoSuchElementException:
            print('Geetest验证视窗未载入,验证失败重新启动')
            self.browser.close()
            self.login()
      except Exception as e:
            print('Geetest验证视窗开启失败,重新启动...意外发生')
            with open('./data/Error_Record.txt', 'a+', encoding='utf-8') as f:
                f.write('Geetest未知错误: ' + Account + ' 使用代理: ' + self.ProxyString + '\n')
                f.close()
             # 截取当前超时页面画面存档
            self.browser.get_screenshot_as_file('./screenshot//' + self.UserID + '_LoginGeetestError.png')
            self.browser.close()
            self.login()# 重新启动登入程序
      else:
            print('Geetest窗口已开启,进行自动验证中...')
            self.GeeTest('//*[@id="region-profile-menu"]/div/div/div/div')# Royalty Icon
错误信息Traceback (most recent call last):
File "d:\Programming\Python\StormBot\start.py", line 183, in login
    self.waitGeetest.until(EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/div/div/div/div')))
File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
Backtrace:
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      GetHandleVerifier
      GetHandleVerifier
      GetHandleVerifier
      GetHandleVerifier
      Ordinal0
      Ordinal0
      Ordinal0
      Ordinal0
      BaseThreadInitThunk
      RtlGetAppContainerNamedObjectPath
      RtlGetAppContainerNamedObjectPath


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\Programming\Python\StormBot\start.py", line 114, in login
    self.browser.get(self.LoginUrl)
File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 436, in get
    self.execute(Command.GET, {'url': url})
File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response      
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id


kallinr 发表于 2022-2-8 13:34:16

木子
页: [1]
查看完整版本: Selenium关于invalid session id错误