【发布时间】:2015-02-08 12:25:03
【问题描述】:
谁能告诉我如何识别并切换到没有标题和 ID 的 iframe。 我需要进入这个框架,以便在这个框架中找到另一个元素来发送一些文本。
<div class="sceditor-container" style="width: 1359px; height: 300px;">
<div class="sceditor-toolbar">
<iframe frameborder="0" src="javascript:false" style="width: 1349px; height: 261px;">
<!DOCTYPE html>
<html style="height:100%">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<link href="" type="text/css" rel="stylesheet">
</head>
<body contenteditable="true" style="height:88%">
<div> </div>
</body>
</html>
</iframe>
为此我写了代码:
WebDriver.SwitchTo().Frame(WebDriver.FindElement(By.TagName("iframe")));
WebDriver.FindElement(By.XPath("html/body")).SendKeys("text");
WebDriver.SwitchTo().DefaultContent();
但 WebDriver 找不到 iframe 元素,因此无法将文本值发送到 iframe 元素。
【问题讨论】:
-
是否抛出了与“No Frame found”相关的异常?