HTML: <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>attribute</title> <script type="text/javascript" async="" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> <script type="text/javascript"> $(document).ready(function(){ $(‘#tooltip‘).tooltip({"placement": "right"}); }); </script> </head> <body> <h3>attribute</h3> <div class="row-fluid"> <div class="span6"> <a id="tooltip" href="#" data-toggle="tooltip" title="watir-webdriver better than selenium-webdriver">hover to see tooltip</a> </div> </div> </body> <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> </html> ====================================================================================================================================================Python Code
# -*- coding: utf-8 -*- from selenium import webdriver from time import sleep import os if ‘HTTP_PROXY‘in os.environ: del os.environ[‘HTTP_PROXY‘] dr = webdriver.Chrome() file_path = ‘file:///‘ + os.path.abspath(‘css.html‘) dr.get(file_path) link = dr.find_element_by_id(‘tooltip‘) print link.value_of_css_property(‘color‘) print dr.find_element_by_tag_name(‘h3‘).value_of_css_property(‘font‘) # 获得tooltip的内容 print link.get_attribute(‘title‘) # 获取该链接的text print link.text
dr.quit()
7. 获取对象的熟悉以及CSS熟悉
时间: 2024-10-08 15:17:53