嗨,我现在还是一个使用Splinter的自动QA测试人员,我想做的是测试一个支付页面,看看是否有提示,如果所需的字段是空的,并将其登录到记事本中。
我的问题是,当我两次使用alert.accept()时,它不会第二次运行。
例如:第一个提示符应该是"Transaction被捕获“,然后我使用alert.accept()关闭提示符。但是第二次它不起作用时,提示符只停留在原来的位置,并且在我使用alert.accept()时不会自动单击ok按钮。为什么会这样呢?当我同时使用两个警报时,是否有一条规则是我遗漏的?
def checkTrappings():
logUtb(f, 'Checking if Transaction type is trapped, making payment with Transaction type as empty')
browser.find_by_id('submitBtn').first.click()
alert = browser.get_alert()
x = str(alert.text)
if x == 'Transaction Type is required.':
logUtb(f, 'Transaction Type input is trapped')
alert.accept()
logUtb(f, "")
logUtb(f, 'Checking if email is a valid email')
browser.select('tranType','A')
browser.find_by_id('submitBtn').first.click()
alert = browser.get_alert()
x = str(alert.text)
if x == 'Please enter a valid email address.':
logUtb(f, 'Proper email format is trapped')
alert.accept()
logUtb(f, "")
browser.find_by_id('submitBtn').first.click()
alert = browser.get_alert()
x = str(alert.text) 顺便说一句,logUtb是我的函数,我将报告记录到记事本上。
def logUtb(fl, strx):
now = datetime.datetime.now()
fl.write(now.strftime('%Y-%m-%d %H:%M') + " - " + strx + "\n");
return;我用的库是碎片
发布于 2013-09-26 03:05:57
我通过创建两个函数来检查不同的字段来解决这个问题,但是我不知道为什么它会工作,我也不喜欢它,如果您可以创建一个具有相同功能的函数,为什么要创建两个函数。
def checkTrapTransaction():
try:
logUtb(f, 'Checking if Transaction type is trapped, making payment with Transaction type as empty')
browser.find_by_id('submitBtn').first.click()
alert = browser.get_alert()
x = str(alert.text)
if x == 'Transaction Type is required.':
logUtb(f, 'Transaction Type input is trapped')
alert.accept()
logUtb(f, "")
except:
logUtbE(f, "Exception: Please recheck your code")
def checkTrapEmail():
try:
logUtb(f, 'Checking if email is a valid email')
browser.select('tranType','A')
browser.find_by_id('submitBtn').first.click()
alert = browser.get_alert()
x = str(alert.text)
if x == 'Please enter a valid email address.':
logUtb(f, 'Proper email format is trapped')
alert.accept()
logUtb(f, "")
except:
logUtbE(f, "Exception: Please recheck your code")如果你们对这个问题有其他的解决办法,我愿意接受建议,因为我不喜欢我刚才做的修正。谢谢
https://stackoverflow.com/questions/19018444
复制相似问题