无法在way2automation.com上输入用户名和密码

时间:2017-12-16 10:46:19

标签: java selenium automation selenium-chromedriver

尝试在way2automation注册页面输入用户名和密码时收到以下错误消息:

  

org.openqa.selenium.remote.ProtocolHandshake createSession
  信息:检测到的方言:OSS
   org.openqa.selenium.ElementNotVisibleException:元素不可见

以下是我的代码:

public void SignIn() {
    try {
        driver.findElement(By.linkText("Signin")).click();
        Thread.sleep(3000);

        driver.findElement(By.xpath("//*[@id=\"load_form\"]/fieldset[6]/input")).sendKeys("ankit_21");
        driver.findElement(By.xpath("//*[@id=\"load_form\"]/fieldset[7]/input")).sendKeys("automation");

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

还尝试按

搜索元素
findElement(By.name("password")).sendKeys("automation");

没有用。

请帮助

2 个答案:

答案 0 :(得分:0)

要在way2automation username中输入 password registration page ,您可以使用以下代码块:

driver.findElement(By.xpath("//input[@id='user_email']")).sendKeys("ankit_21");
driver.findElement(By.xpath("//input[@id='user_password']")).sendKeys("automation");

答案 1 :(得分:0)

您需要先切换到弹出窗口,在那里执行操作,然后在需要再次操作时切换回主窗口。

String parentWindow = driver.getWindowHandle(); //main window
    WebElement loginButton = driver.findElement(By.className("btn-primary"));
    loginButton.click();

    Set<String> handles = driver.getWindowHandles(); //gets all the windows (this code assumes there are only two in total
    for (String windowHandle : handles) {
        if (!windowHandle.equals(parentWindow)) {
            driver.switchTo().window(windowHandle); //switches to the popup window
        }
    }

    WebElement usernameField = driver.findElement(By.id("user_email"));
    usernameField.click();
    usernameField.sendKeys("ankit_21");
    WebElement passwordField = driver.findElement(By.id("user_password"));
    passwordField.click();
    passwordField.sendKeys("automation");

    driver.close(); //close child window
    driver.switchTo().window(parentWindow); //control the parent window