
python for循环中,第二次定位不到元素问题
在进行python登录参数化测试时,出现了for循环第二遍执行报错,无法定位元素的问题。
此问题是由以下原因引起的:
解决方案:
立即学习“Python免费学习笔记(深入)”;
将浏览器的调用放置在for循环内,即可解决此问题。
import unittest
import time
import xlrd
from selenium import webdriver
def test(self):
tabls = excel_table_byindex(file='./data/meit.xlsx')
print(tabls)
if (len(tabls) <= 0):
assert 0, u"数据异常"
for i in range(0, len(tabls)):
self.dr = webdriver.Firefox()
self.dr.maximize_window()
self.dr.implicitly_wait(10)
self.dr.get("https://passport.meituan.com/account/unitivelogin?service=www&continue=http%3A%2F%2Fwww.meituan.com%2Faccount%2Fsettoken%3Fcontinue%3Dhttps%253A%252F%252Fwww.meituan.com%252F")
time.sleep(5)
print(i)
print(tabls[i]['username'])
print(tabls[i]['password'])
# 登录
self.dr.find_element_by_id('login-email').send_keys(tabls[i]['username'])
self.dr.find_element_by_id("login-password").send_keys(tabls[i]['password'])
self.dr.find_element_by_class_name('btn').click()
time.sleep(3)
self.dr.close()以上就是Python for循环中第二次定位不到元素问题:为什么我的代码无法找到元素?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号