Selenium3 automated testing [12] element positioning cognition

Web pages are mainly composed of HTML, CSS, and JavaScript scripts. With the development of Internet technology, most of the current pages are dynamic pages.
Various visual elements in web pages, such as text boxes, buttons, check boxes, pictures, hyperlinks, tables, etc. These elements are called WebElements in Selenium, and are often called objects in other automation tools (such as UFT).
When we want Selenium to operate the browser automatically, we must tell Selenium how to locate the element.

Everyone knows that a Web page is composed of HTML, CSS, JavaScript, etc. You can understand this information by viewing the page source file, and then you can find the desired element tag (Tag), and know the attributes and attribute values ​​of the corresponding elements. And the structure of the page. Take the Bing search page as an example, as shown in Figure 5-1.
Selenium3 automated testing [12] element positioning cognition
The corresponding HTML code is:

<form action="/search" onsubmit="var id = _ge('hpinsthk').getAttribute('h'); return si_T(id);" role="none">
    <div class="b_searchboxForm" role="search" data-bm="15">
        <input class="b_searchbox" id="sb_form_q" name="q" title="输入搜索词" 
type="search" value="" maxlength="100" autocapitalize="off" autocorrect="off" 
autocomplete="off" spellcheck="false" aria-controls="sw_as" aria-autocomplete="both" 
aria-owns="sw_as">
        <div id="sb_go_par" data-sbtip="搜索网页">
            <input type="submit" class="b_searchboxSubmit" id="sb_form_go" tabindex="-1" 
name="go">
        </div>

        <div id="sw_as" role="listbox" aria-label="建议" style="display: block; margin-left: -
1px; margin-right: 1px;">
            <div class="sa_as" data-priority="2" data-bm="20"></div>
        </div>
    </div>
</form>

Through the code of the Web page, you can see that searching for such elements uses the <input> tag embedded in the <form> tag.
The <input> tag of the search box contains attributes such as id, class, and name.
&lt;input class="b_searchbox" id="sb_form_q" name="q" title="输入搜索词" type="search" value="" maxlength="100" autocapitalize="off" autocorrect="off" autocomplete="off" pellcheck="false" aria-controls="sw_as" aria-autocomplete="both" aria-owns="sw_as"&gt;

[Test the full series of video courses] Please click on me.....

Selenium3 automated testing [12] element positioning cognition


Books are available on JD.com and Dangdang on
JD.com: https://item.jd.com/12784287.html
Dangdang: http://product.dangdang.com/29177828.html


Selenium3 automated testing [12] element positioning cognition

Guess you like

Origin blog.51cto.com/starpoint/2593402