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.