7. 获取对象的熟悉以及CSS熟悉
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()
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。