本節(jié)知識(shí)點(diǎn):
多層框架或窗口的定位:
switch_to_frame()
switch_to_window()
智能等待:
implicitly_wait()
對(duì)于一個(gè)現(xiàn)代的web應(yīng)用,經(jīng)常會(huì)出現(xiàn)框架(frame) 或窗口(window)的應(yīng)用,這也給我們的定位帶來了一個(gè)難題。
有時(shí)候我們定位一個(gè)元素,定位器沒有問題,但一直定位不了,這時(shí)候要檢查這個(gè)元素是否在一個(gè)frame中,seelnium webdriver 提供了一個(gè)switch_to_frame方法,可以很輕松的來解決這個(gè)問題。
frame.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>frame</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(){
});
</script>
</head>
<body>
<div class="row-fluid">
<div class="span10 well">
<h3>frame</h3>
<iframe id="f1" src="inner.html" width="800",
height="600"></iframe>
</div>
</div>
</body>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</html>
inner.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>inner</title>
</head>
<body>
<div class="row-fluid">
<div class="span6 well">
<h3>inner</h3>
<iframe id="f2" src="http://www.baidu.com" width="700"
height="500"></iframe>
<a href="javascript:alert('watir-webdriver better than
selenium webdriver;')">click</a>
</div>
</div>
</body>
</html>