21. Get the CSS properties of the test object

Source: Internet
Author: User

Scene

When your test case is tangled in detail, you need to verify that your operation has achieved the desired effect by judging the CSS properties of the element. For example, you can verify that the page's display matches your expectations by judging the font size of the headings on the page. Of course, this is strongly not recommended . Because the most unstable on the page is the CSS, CSS changes frequently, and through the properties can not be intuitive to judge the display of the page, it is better to let people look at a glance, big problem a look is known.

The following code shows how to get the CSS properties of a test object.

Css.html
    <HTML>        <Head>            <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8" />            <title>Attribute</title>                    <Scripttype= "Text/javascript"Async=""src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></Script>            <Linkhref= "Http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css"rel= "stylesheet" />                    <Scripttype= "Text/javascript">$ (document). Ready (function(){                    $('#tooltip'). tooltip ({"Placement": " Right"});            }); </Script>        </Head>                    <Body>            <H3>Attribute</H3>            <Divclass= "Row-fluid">                <Divclass= "Span6">                            <aID= "tooltip"href="#"Data-toggle= "tooltip"title= "Watir-webdriver better than Selenium-webdriver">Hover to see ToolTip</a>                </Div>                    </Div>                </Body>        <Scriptsrc= "Http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></Script>    </HTML>

Note: css.html and test.py are placed in the same folder

Create test.py Enter code

 fromSeleniumImportWebdriver fromTimeImportSleepImportOSDR=Webdriver. Chrome () File_path='file:///'+ Os.path.abspath ('css.html') Dr.get (file_path) sleep (1) Link= dr.find_element_by_id ('tooltip')Print('color is:'+ Link.value_of_css_property ('Color'))Print('font is:'+ Dr.find_element_by_tag_name ('H3'). Value_of_css_property ('Font')) Sleep (1) Dr.quit ()

21. Get the CSS properties of the test object

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.