Automated Test Learning (iv) Validation of selenium command page elements

Source: Internet
Author: User
Tags execution terminates

According to the previous plan, here we will learn how to validate page elements.

----//Validate page elements

Validating the UI elements on the page is the most common feature you use in automating test cases. Selenese validates UI elements in a variety of ways.

For example, are you testing the situation:

(1) A UI element exists in a location on the page;

(2) A particular text exists somewhere on the page;

(3) A specific text exists on the page at the specified location;

If you want to test the text title, then the text content and the top position of the page where it is located, the test case needs care. If you want to test a picture on the home page, but developers often change the location of the picture, you just need to test whether a particular picture exists somewhere on the page.

1.assertion or verification?

Assertion (assertion) or validation (verification) is related to how to manage "failure." The assertion causes the current case to fail and terminates the execution of the case, and validation also causes the case to fail, but allows the case to continue execution.

Code Description:

We open the Selenium download page. Verify the "Downloads" text mark that appears in the code page.

The second line (Asserttitle) and the third line (Verifytext) are "Downloads" when the page is validated, but the program terminates if there is an error in the second row. The third line has an error, giving the error prompt, but does not affect the operation of the four-line program.

2.verifyTextPresent command

Code Description:

Open Taobao homepage, search box type "mobile" keyword, click the search button. We have "mobile" text when we check the page after the search.

The Verifytextpresent command is used to verify that a particular text exists somewhere on the page.

Selenium on the current test page to search for and verify that "phone" exists somewhere. Use when you only care about the existence of specific text on the page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.