python - 如果找不到 item 中的字母之一,我该如何循环它来执行 driver.refresh() 并重试?

标签 python python-2.7 loops selenium python-2.x

如果找不到 item 中的字母之一,我如何循环执行 driver.refresh() 并重试?

for i, item in enumerate(myItemLink):
    if 'B' in item:
      if 'l' in item:
        if 'a' in item:
          if 'c' in item:
            if 'k' in item:
              rightItemIndex.append(i)

最佳答案

假设您只想在测试完所有字母'B'、'l'、'a'、'c'、'k后执行driver.refresh() 'myItemLink 中的每个项目中,您可以使用以下内容:

appended = False

while not appended:
    for i, item in enumerate(myItemLink):
        if all([x in item for x in ['B', 'l', 'a', 'c', 'k']]):
            rightItemIndex.append(i)
            appended = True
            break
    else:
        driver.refresh()

关于python - 如果找不到 item 中的字母之一,我该如何循环它来执行 driver.refresh() 并重试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49080744/

相关文章:

python - for - else 与 elif

php - 在 PHP 中循环遍历 Unix 时间戳范围内的所有日期

c++ - 遍历多种类型

python - 在字符串输入中使用数字,Python 3

python - 读取文件行并在数字之前获取单词

python - 字符串中隐藏的 unicode 字符集

python-2.7 - 如何在 scikit_learn 中的 KFold 中使用 shuffle

python - 当值超过阈值时不同的标记颜色

c - 无法在C程序中的for循环外使用变量值

python - 不能 pip microsoft azure-cognitiveservices-speech?