代码之家  ›  专栏  ›  技术社区  ›  Bobby Mor

无法使用selenium Java或JavascriptExecutor发送密钥/单击

  •  1
  • Bobby Mor  · 技术社区  · 6 年前

    这些是我的代码正在运行的步骤。

    我用secure shell应用程序启动chromedriver-没有问题,它可以正确启动浏览器和应用程序

    chromeOptions.addExtensions(new File("src/test/resources/win32/browserprofile/Secure-Shell-App_v0.8.43.crx"));
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    

    然后,我使用驱动程序导航到chrome URL设置页面以发送连接数据。

    driver.get("chrome-extension://pnhechapfaindjhompbnflcldabbghjo/html/nassh.html");
    

    在下面图像的页面上,我试图发送密钥或单击带有sendkeys的任何字段,或单击,但出现以下错误。 我尝试了多种方法,我得到了相同的结果:org。openqa。硒。WebDriverException:未知错误:无法将属性“value”设置为null

    这是我的密码

    //Webdriver
    driver.findElement(By.xpath("//*[@id='field-description']")).sendKeys("aabb");
    driver.findElement(By.id("field-username")).click();
    driver.findElement(By.id("field-username")).sendKeys("useridval");
    driver.findElement(By.id("field-hostname")).click();
    driver.findElement(By.id("field-hostname")).sendKeys("10.0.0.0");
    
    //JavascriptExecutor 
    // This will execute JavaScript in your script
    ((JavascriptExecutor)driver).executeScript("document.getElementById('field-username').value='migsrcrfuser';");
    

    问:这是否可能,我看到一个id,并且id是唯一的;此外,我还尝试了xpath,得到了相同的结果 。想法

    Secure shell chrome Breift描述:终端仿真器和SSH客户端。 Secure Shell是一个与xterm兼容的终端仿真器,是Chrome的独立ssh客户端。它使用本机客户端直接连接到ssh服务器,而不需要外部代理。 https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd

    2 回复  |  直到 4 年前
        1
  •  1
  •   arnavakhoury    6 年前

    从更新ChromeDriver至2.37(最新版本) https://sites.google.com/a/chromium.org/chromedriver/downloads

    我认为您使用的是Chrome v65

        2
  •  0
  •   Bobby Mor    6 年前

    该问题与框架相关。我使用此代码来确定有多少帧,然后将关键帧发送到正确的帧。呸!

        int size = driver.findElements(By.tagName("iframe")).size();
        System.out.println(size);
    
        driver.switchTo().frame(1); // Switching the inner Frame with 1 0 for outer fram
        driver.findElement(By.xpath("//*[@id='field-description']")).sendKeys("9109");