2012-07-18 54 views
0

我正在使用硒來測試一個android web應用程序。我的測試最初運行良好,但在特定點上掛起。它選擇網頁上的第一個文本字段,並在放大模式下寫入值,但在此處掛起而不選擇第二個文本字段。我哪裏錯了?android模擬器在運行硒腳本時掛起

我的代碼如下:

公共無效testRegister()拋出異常 {

  driver.get("file:///android_asset/www/aboutus.html"); 
    driver.findElement(By.xpath("html/body/div/div/ul/li[2]")).click(); 
    List<WebElement> w1=driver.findElements(By.tagName("input")); 
    System.out.println(w1.size()); 
    for(int i=0;i<w1.size();i++) 
    { 
    System.out.println("************"); 
      System.out.println(i + w1.get(i).getAttribute("id") +"*****" + w1.get(i).getAttribute("name")); 

    } 

    for(WebElement option:w1) 
    { 
      String str=option.getAttribute("id"); 

      if(str.equals("name")) 
      { 
       option.click(); 
       option.sendKeys("Vaishali"); 
      } 

      else if(str.equals("dateofbirth")) 
      { 
       option.click(); 
       option.sendKeys("28-09-1991"); 
      } 

      else if(str.equals("club")) 
      { 
       option.click(); 
       option.sendKeys("Manchester United"); 
      } 

      else if(str.equals("username")) 
      { 
       option.click(); 
       option.sendKeys("vishchan"); 
      } 
      else if(str.equals("password")) 
      { 
       option.click(); 
       option.sendKeys("vishchan"); 
      } 
      else if(str.equals("sendbutton")) 
      { 
       option.click(); 

      } 

} 

回答

2
  1. 的ID可以是 '' 和it'l在返回空值
  2. 元素列表可以隱藏元素與相同的ID 更多的原因請發佈堆棧跟蹤。 最好的問候塔拉斯