【发布时间】:2017-02-22 17:28:02
【问题描述】:
我们的应用程序中有一个富文本编辑器,我们正在使用 selenium 对其进行自动化。以下是相同的 html。
<iframe style="height: 76px; width: 1004px;"></iframe>
<html><head></head><body spellcheck="false"></body></html>
<head></head>
<body spellcheck="false"></body>
<html><head></head><body spellcheck="false"></body></html>
<iframe style="height: 76px; width: 1004px;"></iframe>
<div class=""><iframe style="height: 76px; width: 1004px;"></iframe></div>
<textarea class="form-control Editor" name="actionUpdate" id="actionUpdateId" style="display: none;"></textarea>
我尝试了多种选择。以下代码在 chrome 浏览器上运行良好
driver.switchTo().frame(0);
WebElement el = driver.switchTo().activeElement();
new Actions(driver).moveToElement(el).perform();
driver.findElement(By.xpath("/html/body")).sendKeys("Check");
但是它在 IE11 浏览器上不起作用,因为它无法使用 xpath 找到元素。 两种浏览器之间的区别在于,当我使用 IE 在文本字段中输入内容时,它会转到 textarea 标签。但是在 chrome 中,它输入 body tag 。我曾尝试在 IE 中使用 ID="actionUpdateID" 查找元素,但它会抛出一个异常,提示元素未显示,可能是因为 style="display : none;"
【问题讨论】:
-
这真的是完整的
XPath吗?这对我来说似乎不对。 -
是的,这就是完整的 xpath,因为我正在切换到 iframe,也许这就是为什么它可以正常使用 /html/body
标签: internet-explorer selenium iframe selenium-webdriver textarea