Analysis of the advantages and disadvantages of DOM,XPATH,CSS positioning Web Page object in Selenium automation

Source: Internet
Author: User
Tags xpath

accelerate the efficiency of Internet Explorer Automation: Analysis of the advantages and disadvantages of DOM,XPATH,CSS positioning Web page objects in selenium automation

1. Technical background in the Web application, the user enters the input box through the keyboard input value and the mouse clicks the button, the link and so on. For example, enter the correct user name and password in the User name input box and password input box, then click the login button to log in. In selenium automation, Selenium provides a variety of APIs to manipulate HTML elements, an identifier that can be identified for each HTML element, called a locator in selenium, selenium supports many different types of locators, identifiers, Id,name, DOM Locator,xpath Locator, and CSS Locator. This article focuses on the advantages and disadvantages of DOM, XPATH, and the use of CSS locators in different browsers, as well as considerations.

2. Issues and challenges for a Web Automation project that uses selenium RC, a flexible, concise XPath locator is used on Firefox in the early stages of the project to manipulate objects in the application. However, when the project was launched to 1/3, the need for Internet Explorer support was increased. After running with an existing XPath-based script, it was found that the script ran dozens of times more and the script spent 1 minutes on Firefox took 10-20 minutes, or even longer, on IE. This problem causes the script to become impractical before it is run directly on IE. To understand that Firefox supports native XPath parsing, IE does not support native XPath parsing, but is based on an external JavaScript library (Google's library) for XPath parsing. Since the requirement is to require scripts to support both Firefox and IE browsers, there is a need to look for a different way to make calls to the Selenium API on various browsers to perform the same amount of time.

3. Solution in Selenium RC 0.9.2, the time it takes to parse an XPath's JavaScript library to execute on IE increases the execution time of the script, and the more complex the page, the longer the time spent in IE to raise the API. So I decided to switch to another type of locator, because most of the HTML elements in the Web app you're testing don't have the ID and name attribute specified, so we'll start with a more flexible Dom locator.

Using the DOM locator to position the HTML element, the locator expression needs to be "dom=" or "document." In the beginning, selenium executes this piece of JavaScript to finally get the HTML element we need to access, so in the DOM locator, you can use the DOM object in the Web page to get all the HTML elements within the document. It is important to note that when selenium executes this piece of JavaScript, it is the value of the entire JavaScript script execution, which is the last expression in the JavaScript fragment.

After using the DOM locator, the script executes much less time on IE than when using XPath, which is basically equivalent to the time spent on Firefox.

?

Analysis of the advantages and disadvantages of DOM,XPATH,CSS positioning Web Page object in Selenium automation

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.