为什么for循环不移动到列表中的第二项



我有一个嵌套循环,它应该在列表中的第一个项目上工作,但随后结束不知道为什么第二项不动

serials =['BHT350018400', 'BHTM0016380']
url_latency = 'https://my_company/ui/index.html#'
file_system_start_string = '/filesystems/unif/'
file_system_end_string = '__FILESYSTEM__fs_'
section = 'performance'
count = 1
file_system_count = (str(count))
for serial in serials:
for file in serial:
while count < 5:
full_url = url_latency + file_system_start_string + serial + file_system_end_string + file_system_count + '/' + section
driver.get(full_url)
driver.maximize_window()
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="shell-plugin-area"]/div/div/div/div[2]/ciq-tab-panel/div/div/div/div[3]/div/div/div/div/div/div/div[2]/ciq-performance-details/div/div[1]')))
screenShot_path =  "screengrab" + file_system_count + ".png"
screenshot = driver.save_screenshot(file_path +  screenShot_path)
time.sleep(1)
count += 1
file_system_count = (str(count))
print(full_url)

您需要重置'count'变量像这样,例如:

serials =['BHT350018400', 'BHTM0016380']
url_latency = 'https://my_company/ui/index.html#'
file_system_start_string = '/filesystems/unif/'
file_system_end_string = '__FILESYSTEM__fs_'
section = 'performance'
count = 1
file_system_count = (str(count))
for serial in serials:
for file in serial:
count=1 # <------------ here
while count < 5:
full_url = url_latency + file_system_start_string + serial + file_system_end_string + file_system_count + '/' + section
driver.get(full_url)
driver.maximize_window()
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="shell-plugin-area"]/div/div/div/div[2]/ciq-tab-panel/div/div/div/div[3]/div/div/div/div/div/div/div[2]/ciq-performance-details/div/div[1]')))
screenShot_path =  "screengrab" + file_system_count + ".png"
screenshot = driver.save_screenshot(file_path +  screenShot_path)
time.sleep(1)
count += 1
file_system_count = (str(count))
print(full_url)

或其他任何地方,取决于程序逻辑

最新更新