(十四)WebDriver.findElement()和WebElement.findElement()之間的區別

 
	 @Test
	  public void testUntitledTestCase() throws Exception {
		    driver.get("file:///C:/Users/a/Desktop/select1.html");
		    
		   WebElement div=driver.findElement(By.id("oo"));
		   List<WebElement> rows=div.findElements(By.tagName("li"));
		   System.out.println(rows.size()); //3 限定範圍在id=oo的div中
		   	
	 }
	 
	 
	 @Test
	  public void testUntitledTestCase() throws Exception {
		    driver.get("file:///C:/Users/a/Desktop/select1.html");
		    
		 
		   List<WebElement> rows=driver.findElements(By.tagName("li"));
		   System.out.println(rows.size());//6 範圍在整個頁面
		   	
	 }

 WebDriver.findElement()和WebElement.findElement()之間的區別:

 WebDriver.findElement():是整個頁面中根據條件篩選元素

WebElement.findElement():是從某個元素的區域內根據條件篩選元素

 

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Checkbox</title>
</head>
<body>
<h3>table</h3>                        
<div id="oo">
        <ul>
              <li>
                 <h3>aa</h3>
              </li>
            <li>
                <h3>bb </h3>
             </li>   
            
   <li>
                <h3>cc </h3>
             </li>   

   </ul>  
</div>
<div id="qq">
        <ul>
              <li>
                 <h3>aa</h3>
              </li>
            <li>
                <h3>bb </h3>
             </li>   
            
   <li>
                <h3>cc </h3>
             </li>   
</ul>
 </div>    
</body>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章