应用thread.sleep和隐式等待后无法定位元素

时间:2014-05-06 11:20:28

标签: selenium-webdriver

在应用thread.sleep和Implicit wait之后,我无法找到该元素。抛出以下错误:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"serverName"}
Command duration or timeout: 10.09 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_25'
Session ID: f66446c1-f261-4c90-b74f-b4a5ecce3eb4
Driver info: org.openqa.selenium.firefox.FirefoxDriverpublic void testEmptydatabase() throws Exception {



driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.linkText("Home")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.cssSelector("u")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.id("monitor")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.cssSelector("span.ui-icon.ui-icon-plus")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
   driver.findElement(By.cssSelector("#add_profileDetailTable > div.ui-pg-div")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileName")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileName")).sendKeys("new");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileDescription")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileDescription")).sendKeys("test");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.name("createProfile")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("serverName")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("serverName")).sendKeys("192.168.32.16");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.xpath("(//input[@name='monitors'])[11]")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("nextStep")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("userPassword")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

  driver.findElement(By.id("userPassword")).sendKeys("root");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.xpath("//button[@value='Establish Connection']")).click();
  try {
    assertTrue(driver.findElement(By.cssSelector("div.formErrorContent")).getText().matches("^exact:[\\s\\S]* This field is required$"));
  } catch (Error e) {
    verificationErrors.append(e.toString());
  }
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("fancybox-close")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);


}
    Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=22.0}]

I dont want to change the version of selenium and browser.


public void testEmptydatabase() throws Exception {

    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.linkText("Home")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.cssSelector("u")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.id("monitor")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
      driver.findElement(By.cssSelector("span.ui-icon.ui-icon-plus")).click();
      driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
   driver.findElement(By.cssSelector("#add_profileDetailTable > div.ui-pg-div")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileName")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileName")).sendKeys("new");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileDescription")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("profileDescription")).sendKeys("test");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.name("createProfile")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("serverName")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  **driver.findElement(By.id("serverName")).sendKeys("192.168.32.16");**
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.xpath("(//input[@name='monitors'])[11]")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("nextStep")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("userPassword")).clear();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

  driver.findElement(By.id("userPassword")).sendKeys("root");
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.xpath("//button[@value='Establish Connection']")).click();
  try {
    assertTrue(driver.findElement(By.cssSelector("div.formErrorContent")).getText().matches("^exact:[\\s\\S]* This field is required$"));
  } catch (Error e) {
    verificationErrors.append(e.toString());
  }
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
  driver.findElement(By.id("fancybox-close")).click();
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);


}

请查看代码。并建议做什么。另外有人建议我不要使用Thread.sleep所以我使用了Implicit等待,但是我尝试使用thread.sleep,但是也没有使用它。

0 个答案:

没有答案