python - 为什么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)
或其他任何地方,取决于程序逻辑
推荐阅读
- android - android.support.design.widget.BottomNavigationView 如何更改未选中项目的图标而不仅仅是色调
- unit-testing - 如何设置赛普拉斯进行单元测试?
- python - 错误 python 包版本:RequestsDependencyWarning:urllib3 (1.7.1) 或 chardet (2.0.1) 与支持的版本不匹配
- java - Gradle 不会用 gradle.properties 变量填充文件
- visual-studio - 在 Unity3D 中单击角色时创建弹出菜单 Sims 的样式
- jekyll - Jekyll/Rouge - 突出显示的嵌套代码块
- couchbase - 如何通过 SDK 更新 couchbase 中的数组
- sql-server-2008 - 如何基于逗号分隔的字符串列表创建“联合”
- html - 为什么我在 Mailchimp 中的 html 模板看起来与我在 gmail 桌面/移动设备上收到的不同
- jquery - 如何通过单击按钮将 a 的单元格值通过 ajax 传递给控制器?