问答 新手求教:python+selenium 实现 WEBUI 自动化时如何对按钮无法点击进行断言

林夕 · 2021年04月19日 · 最后由 林夕 回复于 2021年04月20日 · 2459 次阅读

未输密码登录按钮为不可点状态,如何实现断言

# 点击登陆
self.driver.find_element_by_xpath('//button[@type="button"]').click()

共收到 4 条回复 时间 点赞

用 get_attribute 方法获取属性值来进行断言

'''判断某个元素是否可见并且是可点击的,如果是的就返回这个元素,否则返回 False'''
WebDriverWait(driver,10,0.1).until(EC.element_to_be_clickable((locator)))

谢谢大家,最后用这个断言成功了 self.assertFalse((self.driver.find_element_by_xpath('//button[@type="button"]')).is_enabled())
print('测试通过')

林夕 关闭了讨论 04月20日 11:54
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册