我被自动化困住了,当我输入错误的用户名和密码时,它会弹出“无法登录。尝试不同的用户名”
def test_logonWrongUserName(self):
self.setUpClass() # Initialize the driver
self.sh.navigateToUrl("http://test.com")
self.sh.member_Login("Foo", "asd")
现在需要测试警报或弹出窗口(不确定它是警报或弹出窗口),其中包含文本“无法登录。尝试不同的用户名”。如果找到文本,则测试通过。如果不是,那么测试就会失败。
注意:只是想添加,在关闭警报/弹出窗口之前我们无法访问 html dom
你需要等待警报出现 http://selenium-python.readthedocs.io/waits.html#explicit-waits,断言你有预期的text http://selenium-python.readthedocs.io/api.html#selenium.webdriver.common.alert.Alert.text里面然后关闭/accept http://selenium-python.readthedocs.io/api.html#selenium.webdriver.common.alert.Alert.accept警报:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
wait = WebDriverWait(driver, 10)
wait.until(EC.alert_is_present())
alert = driver.switch_to.alert
assert "Unable to login. Try different username" in alert.text
alert.accept()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)