【问题标题】:Unable to Enter Username and Password on way2automation.com无法在 way2automation.com 上输入用户名和密码
【发布时间】:2018-05-30 09:36:50
【问题描述】:

尝试在 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");

效果不佳。

请帮忙

【问题讨论】:

  • 您需要切换到新窗口。
  • 请将代码的html部分粘贴到这里

标签: java selenium automation selenium-chromedriver


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多