【问题标题】:Selenium, You may only interact with visible elements while submitting a password fieldSelenium,您只能在提交密码字段时与可见元素交互
【发布时间】:2018-11-30 06:28:11
【问题描述】:

在开始之前,我已经尝试过......

Selenium Htmlunit org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements

Error:org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements using htmlunitdriver?

Selenium HtmlUnitDriver clicking on checkbox

这些都不适合我...

我已将问题范围缩小到 username.sendKeys("hullo");线

 import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class WebAccessor  {
    public static void main(String[] args) {

        WebDriver driver = new HtmlUnitDriver();
        driver.get("https://portal.mcpsmd.org/public/");

        // Find the text input element by its name
        WebElement username = driver.findElement(By.id("fieldAccount"));
        WebElement password = driver.findElement(By.id("fieldPassword"));

        // Enter something to search for
        username.sendKeys("hullo");

//      WebElement submit = driver.findElement(By.name("btn-enter"));

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        driver.quit();
    }
}

现在,不幸的是,我尝试过的任何方法都无法修复“您只能与可见元素交互”的错误,而且据我所见,这个字段是完全可见的,它在一个小时的挖掘中被正确标记在检查元素字段中。

提前非常感谢。

【问题讨论】:

  • 在 driver.get("portal.mcpsmd.org/public/"); 之后通过包含 Thread.sleep(1500); 进行检查
  • 请添加该字段的 HTML。如果有一个 display 属性使元素隐藏,那么它可以用 JS 克服。
  • 顺便说一句,您的脚本在我的系统上运行得非常好。

标签: java selenium


【解决方案1】:

尝试检查返回的内容

 element.is_displayed()

如果它为 False,那么可能的原因是在 dom 中显示设置为 none,因此限制您输入任何内容。

【讨论】:

    【解决方案2】:

    当我尝试运行代码时,我没有收到任何异常:

    我使用了依赖:

    <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-htmlunit-driver</artifactId>
                <version>2.52.0</version>
            </dependency>
    

    它正在打印文本:“页面标题是:学生和家长登录”

    你应该改变你的 maven 依赖。

    希望对您有所帮助。

    【讨论】:

    • 发现问题了,我用了eclipse自动添加依赖的解决方案,给了我一个过时的selenium版本,谢谢你的帮助!
    猜你喜欢
    • 2017-10-03
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2020-03-26
    相关资源
    最近更新 更多