TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
请问一下,我使用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[69]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
-
- 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[1]/div[1]/div[1]') # 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[69]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
- 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 [0x00626903+2517251]
- Ordinal0 [0x005BF8E1+2095329]
- Ordinal0 [0x004C2848+1058888]
- Ordinal0 [0x004ED448+1233992]
- Ordinal0 [0x004ED63B+1234491]
- Ordinal0 [0x00517812+1406994]
- Ordinal0 [0x0050650A+1336586]
- Ordinal0 [0x00515BBF+1399743]
- Ordinal0 [0x0050639B+1336219]
- Ordinal0 [0x004E27A7+1189799]
- Ordinal0 [0x004E3609+1193481]
- GetHandleVerifier [0x007B5904+1577972]
- GetHandleVerifier [0x00860B97+2279047]
- GetHandleVerifier [0x006B6D09+534521]
- GetHandleVerifier [0x006B5DB9+530601]
- Ordinal0 [0x005C4FF9+2117625]
- Ordinal0 [0x005C98A8+2136232]
- Ordinal0 [0x005C99E2+2136546]
- Ordinal0 [0x005D3541+2176321]
- BaseThreadInitThunk [0x7595FA29+25]
- RtlGetAppContainerNamedObjectPath [0x77047A9E+286]
- RtlGetAppContainerNamedObjectPath [0x77047A6E+238]
-
-
- 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
-
复制代码
|
|