Java Selenium WebDriver登录到MondoZoo

Java Selenium WebDriver登录到MondoZoo,java,selenium-webdriver,Java,Selenium Webdriver,我正在尝试填写的登录表单,但当我尝试查找用户名或密码时,会出现以下异常:org.openqa.selenium.NoSuchElementException 我试过: private static void enterMondoZoo(ChromeDriver driver){ lg.info("Entering in mondoZoo:"); driver.get("http://www.mondozoo.com"); driver.findElement(By.cla

我正在尝试填写的登录表单,但当我尝试查找用户名或密码时,会出现以下异常:
org.openqa.selenium.NoSuchElementException

我试过:

private static void enterMondoZoo(ChromeDriver driver){
    lg.info("Entering in mondoZoo:");
    driver.get("http://www.mondozoo.com");
    driver.findElement(By.className("mbarlog")).click();
    try {
        Thread.sleep(3000); //not the best wait in the world
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.findElementByName("login").sendKeys("random");

    lg.info("Leaving the enteringMondoZoo");
}
我尝试过:
xpath-/*[@id=“loginform”]/div[3]/form/div[1]/p[2]/input

但是没有成功。

显示的登录模型实际上在iframe中。因此,首先必须切换到帧并尝试输入值

private static void enterMondoZoo(ChromeDriver driver){
    lg.info("Entering in mondoZoo:");
    driver.get("http://www.mondozoo.com");
    driver.findElement(By.className("mbarlog")).click();
    try {
        Thread.sleep(10000); //not the best wait in the world
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.switchTo().frame("framebarrelogin");
    //Do all your login actions here
    driver.findElement(By.xpath("//*[@id='loginform']/div[3]/form/div[1]/p[2]/input")).sendKeys("random");
    //Login actions completed
    driver.switchTo().defaultContent();
    lg.info("Leaving the enteringMondoZoo");
}
我使用iframe ID属性切换到帧。您还可以使用索引而不是ID。完成iframe中的所有操作后,使用“driver.switchTo().defaultContent()”切换回主页面

有关处理iFrame的更多详细信息,请访问