【问题标题】:SendKeys not populating the values in respective components in Internet Explorer but it does in ChromeSendKeys 不会填充 Internet Explorer 中各个组件中的值,但它会在 Chrome 中填充
【发布时间】:2018-11-03 12:18:06
【问题描述】:

我遇到了这样的问题,即使在 Internet Explorer 11 中给出了有效 ID,SendKeys() 也没有将值传递到正确的字段。如果我在 Chrome 66+ 浏览器中运行相同的脚本,它会按预期工作。为什么?

脚本:

// Address Line1
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_address1_text")).clear();
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_address1_text")).sendKeys(ADDRESS1);
Thread.sleep(1000)

// City
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_city_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_city_text")).sendKeys(CITY_NAME)
Thread.sleep(1000)

// State
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_state_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_state_text")).sendKeys(STATE_CODE)
Thread.sleep(1000)

// Postal code
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_postalCode_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_postalCode_text")).sendKeys(POSTAL_CODE)
Thread.sleep(1000)

上面提到的脚本取自更新屏幕。所以我正在清除现有内容并将值传递给相应的字段。

问题: 值不匹配,即 AddressLine1 值传递给 CityPostalCode 字段接收 FirstName 值(仅供参考:我没有在剧本中提到)

Chrome 浏览器 中执行相同的脚本时,它可以正常工作。为什么?

有人请给我解决方案吗?

已编辑: 附上截图

谢谢
卡鲁纳加拉潘迪

【问题讨论】:

  • 奇怪,我没有看到定位器标签已更改特定于浏览器,似乎您可能传递了错误的 id
  • 嗨,我没有更改它在 Chrome 浏览器中完美运行的脚本。我也不知道怎么解决.. :(
  • 好的,我会尝试找到解决方案
  • 你能用你用来配置IEDriverServer的代码块更新问题吗?

标签: java selenium automation webdriver internet-explorer-11


【解决方案1】:

这个问题很容易发生。可能是由于错误的驱动程序,错误的驱动程序版本,以及IE实际上是浏览器的灾难。 您可能正确地找到了元素(如果它适用于 Chrome)但是 sendKeys() 方法对于 IE 无法正常工作它有问题,这个问题也发生在 Safari 上。

试试这个,它可能会有所帮助:

对于 64 位 WebDriver: 1.打开IE 2. 转到 Internet 选项 → 高级 → 安全 3. 勾选 ☑ Enable 64-bit processes for Enhanced Protected Mode 点击 4.申请并确定

对于 32 位 WebDriver: 1.打开IE 2. 转到 Internet 选项 → 高级 → 安全 3. 取消选中 ☐ 为增强保护模式启用 64 位进程 4. 点击应用并确定

还有:

Internet 选项 -> 安全 -> 选中所有区域的“启用保护模式” 转到高级 -> 安全 -> 选中“启用增强保护模式”

在代码中试试这个:

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
...
capabilities.setCapability("requireWindowFocus", true);
WebDriver driver = new InternetExplorerDriver(capabilities);

试试这个,但对我来说,这只适用于几个版本的 IE:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('ID').value='VALUE';");

【讨论】:

  • 好答案!!!但是如果Enable Enhanced Protected Mode选中,您可以避免添加INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS。为@JimEvans 的眩光做好准备
【解决方案2】:

我在 Windows 10 64 位操作系统上有 IE11 32 位浏览器和 32 位 IE 驱动服务器。

我可以使用 sendkeys 在编辑字段中输入文本,但之后会被删除。

//WebElement 离开=webControls.getDriver().findElement(By.id("oneWayFlight_fromLocation")); //((JavascriptExecutor) webControls.getDriver()).executeScript("document.getElementById('oneWayFlight_fromLocation').value='JFK'"); //((JavascriptExecutor) webControls.getDriver()).executeScript("arguments[0].value='JFK';",depart); ((JavascriptExecutor) webControls.getDriver()).executeScript(String.format("document.getElementById('oneWayFlight_fromLocation').value='JFK';","JFK"));

JFK 被输入但随后被删除:

【讨论】:

    猜你喜欢
    • 2015-02-13
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    相关资源
    最近更新 更多