【问题标题】:Selenium cannot find element on website (chrome/Java)Selenium 在网站上找不到元素(chrome/Java)
【发布时间】:2015-09-09 01:35:07
【问题描述】:

尝试测试/学习硒登录 错误 - 线程“主”org.openqa.selenium.ElementNotVisibleException 中的异常:元素不可见

package com.indeed.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class test1 {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", 
        "C:\\Users\\****\\Desktop\\neww\\trainingfiles\\chromedriver.exe.exe");
        WebDriver driver = new ChromeDriver();

        driver.get("http://www.neopets.com/login/index.phtml");
        driver.findElement(By.name("username")).sendKeys("test1");
    }
    private static void sleep(int i) {
    }
}

【问题讨论】:

  • edit添加一个具体的问题陈述——可以假设“它不起作用”,但是如何它不起作用?什么错误信息或不正确的行为是特征? (另外,你没有右括号,所以你发布的代码无法编译。)
  • 感谢提示,已编辑!

标签: java google-chrome selenium login


【解决方案1】:

我看过那个网页。问题是有两个名为“用户名”的输入字段。其中之一是不可见的。可能 Selenium 正在得到那个。你应该做的是:

List<WebElement> elements = driver.findElements(...);

然后得到第二个(或第一个,无论如何),然后尝试:

elements.get(1).sendKeys(...);

【讨论】:

  • 谢谢这绝对是问题所在,如果我点击顶部的“登录”它会填写信息,所以我可以先在“登录”元素上单击()然后它会起作用,但是当我检查它时,“登录”没有与之关联的类或名称,你知道我如何在那个元素上 .click() 吗?
猜你喜欢
  • 2021-08-29
  • 2020-03-24
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 2017-07-17
  • 1970-01-01
  • 2019-04-03
  • 2019-04-16
相关资源
最近更新 更多