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