![](/img/trans.png)
[英]Why does generated PDF display properly in Internet Explorer but not in FireFox or Chrome?
[英]SendKeys not populating the values in respective components in Internet Explorer but it does in Chrome
我面临这样的问题,即使在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值传递给City和PostalCode字段接收FirstName值(仅供参考:我没有在脚本中提到)
在Chrome 浏览器中执行相同的脚本时,它可以正常工作。 为什么?
有人请给我解决方案吗?
谢谢
卡鲁纳加拉班迪
这个问题往往会发生。 可能是由于错误的驱动程序,错误的驱动程序版本,以及IE实际上是浏览器的灾难。 您可能正确地找到了元素(如果它适用于 Chrome),但是 sendKeys() 方法对于 IE 无法正常工作,它有问题,这个问题也发生在 Safari 上。
尝试其中之一,它可能会有所帮助:
对于 64 位 WebDriver: 1. 打开 IE 2. 转到 Internet 选项 → 高级 → 安全 3. 选中 ☑ 启用 64 位进程以增强保护模式 单击 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';");
我在 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 被输入但随后被删除:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.