Box automated testing experience how to do?

First, the understanding of the dialog box
Web page dialog box is a very common type of control, when we use the buttons common element positioning method for positioning a dialog box will find the location fails, how do we do this time? To accurately locate, we it is necessary to understand the next dialog box. In general, alert dialog box has three kinds: Alert, prompt, confirm.

  1. alert () alert box, click on the pop-up alert box that contains a certain button. Warning message box alert in a parameter, the developers want users to see text that is not in HTML format. It provides an "OK" button allows the user to close the alert box, and an alert box is modal window, that is, the user must close the message box before you can proceed.

  2. confirm () check box, when clicked, will pop up a confirmation box contains OK and Cancel buttons. Check box to use the confirmation message box asking "yes or no" to the user, the user can choose to click "OK" button or click "Cancel" button to return value, confirm method is a Boolean value. It is also a modal window, the user must close the dialog box to the next step.

  3. prompt () prompt box, click on the OK button will pop up containing a cancel button and a message box text box, the user can enter an answer in response to the prompt box in a text box. When the user enters information in the text box, and click "OK" button, and the page will respond. It is also a modal window, the user must close the dialog box to the next step.

Second, processing dialog

  1. For these three dialog boxes in the way we deal with selenium is the same:
    (1) driver.switch_to.alert obtain Alert
    (2) alert.accept () to accept the dialog box options (equivalent to clicking OK)
    (3) alert.dismiss () to cancel the dialog box options
    (4) alert.text return a text message dialog
  2. Alert alert box

    Click the button to get a warning box

    driver.find_element_by_css_selector("#alert").click()
    sleep(2)

    Gets the warning box

    alert = driver.switch_to.alert

    Gets the warning box text

    print ( "warning message box text is:", alert.text)

    Accept the warning box (Click the OK button)

    alert.accept()
    sleep(2)

    Click again

    driver.find_element_by_css_selector("#alert").click()

    Gets the warning box

    alert = driver.switch_to.alert
    sleep(2)

    Cancel alert box (click the close button X)

    alert.dismiss()

  3. Confirm confirmation box

    Click the button to get a confirmation box

    driver.find_element_by_css_selector("#confirm").click()
    sleep(2)

    Obtain confirmation box

    alert = driver.switch_to.alert

    Obtain confirmation box text

    print ( "confirmation box text information:", alert.text)

    Receiving confirmation box (click the OK button)

    alert.accept()
    sleep(2)

    Click for again

    driver.find_element_by_css_selector("#confirm").click()
    alert = driver.switch_to.alert
    sleep(2)

    Cancel confirmation box (click the Cancel button)

    alert.dismiss()

  4. Prompt prompt box

    Click the button to get a prompt box

    driver.find_element_by_css_selector("#prompt").click()
    sleep(2)

    Get tips box

    alert = driver.switch_to.alert

    Get tips box text

    print ( "balloon text message as:", alert.text)
    SLEEP (2)

    Tip box for typing text box

    alert.send_keys("www.ujiuye.com")

    Accept the prompt box (Click the OK button)

    alert.accept()
    sleep(2)

    Click for again

    driver.find_element_by_css_selector("#prompt").click()
    alert = driver.switch_to.alert

    Tip box for typing text box

    alert.send_keys("www.offcn.com")
    sleep(2)

    Cancel prompt box (click the Cancel button)

    alert.dismiss ()
    by the above case, the next encounter dialog box, you can locate it? Want to learn more knowledge of software testing, then we can continue to focus our section.
    Want to know more courses in software testing, software testing adding excellent employment exchange group it, within the group will have a full-time teacher for you answering questions. In addition there will be occasional free live within the group lessons, taught by lecturers active duty. There are still active five days free trial to learn, got it, quickly join it. Click the plus group group number: 617 089 523 (in order to provide more efficient service, please note signal when the additive group: Collar information)

Guess you like

Origin blog.51cto.com/14669527/2471459