- 如果是打开网址,直接driver.get(url)即可
driver.get("http://www.baidu.com")
- 如果是打开本地的html文件
driver.get("file:///Users/xxxxxxxx/files/python/selfPractise/selenium_yo/selenium_report/unittest_selenium/aa.html")
方法是:在finder中选中html文件,右键-->打开方式中选chrome,完成。
python操作该页面:
driver = webdriver.Chrome()
driver.get("file:///Users/xxxxxxxx/files/python/selfPractise/selenium_yo/selenium_report/unittest_selenium/aa.html")
driver.find_element_by_link_text("fruit1").click()
WebDriverWait(dr, 10).until(lambda the_driver: the_driver.find_element_by_id('dropdown1').is_displayed())
menu = driver.find_element_by_id('dropdown1').find_element_by_link_text('banana')
#menu = driver.find_element_by_xpath("//*[@id='dropdown1']/li[3]/a")
#上面的这两句是一样的效果
#鼠标定位到子元素上
webdriver.ActionChains(driver).move_to_element(menu).perform()
slepp(5)
driver.close()
如下html代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Level Locate</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" />
</head>
<body>
<h3>Level locate</h3>
<div class="span3">
<div class="well">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">fruit1</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel" id="dropdown1" >
<li><a tabindex="-1" href="#">apple</a></li>
<li><a tabindex="-1" href="#">banana</a></li>
<li><a tabindex="-1" href="#">orange</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">grape</a></li>
</ul>
</div>
</div>
</div>
<div class="span3">
<div class="well">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">fruit2</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel" >
<li><a tabindex="-1" href="#">apple</a></li>
<li><a tabindex="-1" href="#">banana</a></li>
<li><a tabindex="-1" href="#">orange</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">grape</a></li>
</ul>
</div>
</div>
</div>
</body>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</html>