【发布时间】:2014-12-03 13:10:25
【问题描述】:
编辑:
元素在 iframe 中,这就是它最终的工作方式:
WebDriverWait wait = new WebDriverWait(_driver, 60);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By
.xpath("//*[@class='IFrameID']")));
WebElement element_t = _driver.findElement(
By.xpath("//*[@myattribute='mytest']"));
编辑:
我的问题似乎是页面的结构。我尝试了不同的东西,我只能通过 id 获取正文,我试图通过 id 获取的其他元素或任何其他属性都找不到...
我正在尝试使用 By.xpath 方法获取元素,xpath 本身在 firebug/firepath 中使用时工作得很好,但在 java 应用程序中使用时出现异常:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@myattribute='mytest']"}
我尝试访问的属性不是标准的 html 属性,而是从框架生成的,因此该字段如下所示:
<input id="F_19" class="FIELDInputEdit" type="text" style=" width:100%;" maxlength="40" myattribute="mytest" name="CC">
javacode 本身看起来像这样:
WebElement element_t = _driver.findElement(
By.xpath(".//*[@myattribute='mytest']"));
由于唯一已知的属性是这个,我没有其他方法可以访问输入字段。 我正在使用 Firefox 17.0.11
【问题讨论】:
-
我看到一个错字:
myattributvsmyattribute。这是从复制到这里,还是实际问题? -
只是复制... sry
-
您是否尝试过添加等待元素?可能是 selenium 在页面加载之后但在浏览器 javascript 将其添加到页面之前查找它。
-
我现在试过没有效果:
WebElement element_t = (new WebDriverWait(_driver, 10)) .until(ExpectedConditions.presenceOfElementLocated( By.xpath(".//*[@myattribute='mytest']"))); -
您要查找的元素是否在 iFrame 中?
标签: java firefox selenium xpath