首页 \ 问答 \ 多次使用alert.accept()无法正常运行(Using alert.accept() multiple times does not function properly)

多次使用alert.accept()无法正常运行(Using alert.accept() multiple times does not function properly)

嗨,我目前Splinter使用Python作为自动化QA( Splinter )测试人员,我想做的是测试付款页面,看看是否有必要字段为空的提示并将其记录到记事本中。

我的问题是,当我使用alert.accept()两次时,它不会第二次运行。

例如:第一个提示符应该说“事务类型输入被捕获”,然后我使用alert.accept()来关闭提示。 但第二次它不起作用时,提示只是保持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;

我正在使用的库是碎片


Hi I am currently new to being a Automated QA (in Splinter) tester using Python, What I want to do is to test a payment page to see if there are prompts if the required fields are empty and log it into the notepad.

My problem is that when I use alert.accept() twice it does not run the second time around.

For example: The first prompt is expected to say "Transaction Type input is trapped" and then I use alert.accept() to close the prompt. But the second time around it does not work the prompt just stays where it is and does not automatically click the ok button when I use alert.accept(). Why is this? Is there a rule i'm missing when i'm using two alerts at the same time?

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 by the way is my function where I log the report to the notepad

    def logUtb(fl, strx):
  now = datetime.datetime.now()
  fl.write(now.strftime('%Y-%m-%d %H:%M') + " - " + strx + "\n");
  return;

The library i'm using is splinter


原文:https://stackoverflow.com/questions/19018444
更新时间:2022-03-05 08:03

最满意答案

默认情况下,使用${}语法会转义包含的文本(以帮助抵御XSS注入攻击)。

相反,使用structure:前缀来告诉渲染引擎不要转义您的文本:

<div>${structure: body}</div>

Using the ${} syntax escapes the included text by default (to help defend against XSS injection attacks).

Instead, use the structure: prefix to tell the rendering engine to not escape your text:

<div>${structure: body}</div>

相关问答

更多