java - 无法使用 selenium Java 或 JavascriptExecutor 发送按键/单击

标签 java selenium google-chrome-extension selenium-chromedriver

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

我使用安全 shell appt 启动 chromedriver - 没有问题,它可以正确启动浏览器和 appt

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

然后,我使用 driver get 导航到 chrome URL 设置页面以发送连接数据。

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

在下图中的此页面上,我尝试发送 key 或单击带有 sendkeys 的任何字段或单击,但出现以下错误。 我尝试了多种方法,但得到了相同的结果:org.openqa.selenium.WebDriverException:未知错误:无法设置 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 简要描述:终端仿真器和 SSH 客户端。 Secure Shell 是一个与 xterm 兼容的终端模拟器和适用于 Chrome 的独立 ssh 客户端。它使用 Native-Client 直接连接到 ssh 服务器,无需外部代理。 https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd

最佳答案

将您的 ChromeDriver 从 https://sites.google.com/a/chromium.org/chromedriver/downloads 更新到 2.37(最新)

我认为您使用的是 Chrome v65

关于java - 无法使用 selenium Java 或 JavascriptExecutor 发送按键/单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49547881/

相关文章:

java - 使用 Twilio Java Sdk v7.x 将 Twilio Recording 下载为输入流

Java游戏-如何阻止玩家越过障碍物

java - 从加速度传感器写入文件 - android

javascript - 全局变量 Chrome 扩展内容脚本

javascript - 获取 Chrome 扩展程序 "Allow in incognito"打开\关闭的时间

java - 从 Map[String,Any] 类型的 Scala 映射中提取值,其中 Any 可以是 Map 本身

javascript - 如何使用 wdio 处理弹出窗口?

java - 如何使用 Java 和 Selenium 动态映射元素

javascript - 如何在 Protractor 中添加新的元素功能

javascript - 如何测量选项 "Disable Cache"在 Chrome 中是否处于事件状态(通过 JavaScript)