代码之家  ›  专栏  ›  技术社区  ›  DucksEatTurtles

selenium,您只能在提交密码字段时与可见元素交互

  •  0
  • DucksEatTurtles  · 技术社区  · 7 年前

    在我开始之前,我试过…

    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();
        }
    }
    

    现在,不幸的是,我所尝试的没有任何东西可以让我修复“只可以与可见元素交互”的错误,而且从我所看到的,这个字段是非常可见的,它被正确地标记在检查元素字段中的一个小时的挖掘中。

    多谢提前。

    2 回复  |  直到 7 年前
        1
  •  0
  •   dangi13    7 年前

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

    我使用依赖:

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

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

    您应该更改Maven依赖项。

    希望能有所帮助。

        2
  •  0
  •   Sajid Manzoor    7 年前

    尝试检查返回的内容

     element.is_displayed()
    

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