我的腳本對串列中的每輛車都做同樣的事情,但在隨機段落
vec = WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located((
'id', 'elp.jobDetailsVehicle.input.jobVehicleEngineCode'))).get_attribute('value')
找不到元素,我收到此錯誤:
File "script.py", line 79, in check_recall
WebDriverWait(driver, 60).until(
File "C:\Users\Be26.LANGWEDEL\AppData\Local\Programs\Python\Python310\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 [0x0125FDC3 2555331]
Ordinal0 [0x011F77F1 2127857]
Ordinal0 [0x010F2E08 1060360]
Ordinal0 [0x0111E49E 1238174]
Ordinal0 [0x0111E69B 1238683]
Ordinal0 [0x01149252 1413714]
Ordinal0 [0x01137B54 1342292]
Ordinal0 [0x011475FA 1406458]
Ordinal0 [0x01137976 1341814]
Ordinal0 [0x011136B6 1193654]
Ordinal0 [0x01114546 1197382]
GetHandleVerifier [0x013F9622 1619522]
GetHandleVerifier [0x014A882C 2336844]
GetHandleVerifier [0x012F23E1 541697]
GetHandleVerifier [0x012F1443 537699]
Ordinal0 [0x011FD18E 2150798]
Ordinal0 [0x01201518 2168088]
Ordinal0 [0x01201660 2168416]
Ordinal0 [0x0120B330 2208560]
BaseThreadInitThunk [0x76C3FA29 25]
RtlGetAppContainerNamedObjectPath [0x77057A9E 286]
RtlGetAppContainerNamedObjectPath [0x77057A6E 238]
我已經嘗試過類似的條件presence_of_element_located- 同樣的錯誤。這是完全隨機的。有任何想法嗎?
編輯:這是整個回圈:
for line in lines:
if line[3] == '.':
license_plate = line[23:33]
name = line[38:52]
vin = line[88:105]
if '-' in license_plate and 'VSSZZZ' in vin:
driver.switch_to.frame(driver.find_element('id', 'mainFs'))
entry_license_plate = driver.find_element('id', 'elp.searchVehicle.input.licensePlate')
entry_license_plate.send_keys(license_plate)
driver.find_element('id', 'vaws.vehsearch.btn.search').click()
vec = WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located((
'id', 'elp.jobDetailsVehicle.input.jobVehicleEngineCode'))).get_attribute('value')
WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located(('id', 'vaws.sys.recall')))
try:
recall = driver.find_element('id', 'recall.info.state').get_attribute('src')
except NoSuchElementException:
recall = driver.find_element('id', 'recall.info.warning').get_attribute('src')
if 'dummy.gif' in recall or 'info.gif' in recall:
recall = 'Nein'
elif 'warning.gif' in recall:
recall = 'Ja'
final_list = f'{name} | {license_plate} | {vin} | Motor-Kennbuchstabe: {vec} ' \
f'| Feldma?nahme: {recall}\n'
print('done')
driver.switch_to.default_content()
WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located(('id', 'toolbar.button.new.job'))).click()
該頁面是我們公司的內部站點,所以我不允許顯示它。
uj5u.com熱心網友回復:
這只是意味著 60 秒超時結束而沒有觀察until方法中的內容。
嘗試將其放入 try 中:
try:
vec = WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located((
'id', 'elp.jobDetailsVehicle.input.jobVehicleEngineCode'))).get_attribute('value')
except:
print("Timeout")
或者,再試一次,直到我們沒有錯誤:
while True:
try:
vec = WebDriverWait(driver, 60).until(
expected_conditions.visibility_of_element_located((
'id', 'elp.jobDetailsVehicle.input.jobVehicleEngineCode'))).get_attribute('value')
# break out of the loop if successful
break
except:
# continue the loop if not successful
continue
print("Timeout")
uj5u.com熱心網友回復:
好的,我想我發現了問題:一開始我加載了默認組態檔
options.add_argument(f'--user-data-dir={os.getenv("LOCALAPPDATA")}\\Google\\Chrome\\User Data'
沒有它,我就沒有這些隨機錯誤。有誰知道為什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421997.html
標籤:
