Java 如何在selenium RC中键入iframe?

Java 如何在selenium RC中键入iframe?,java,iframe,selenium,types,selenium-rc,Java,Iframe,Selenium,Types,Selenium Rc,html页面的结构如下所示: <html> <body> <iframe id="iframe-id"> #document <html> <body contenteditable="true"> </body> </html> </iframe> </body> </html> Sel

html页面的结构如下所示:

<html>
  <body>
    <iframe id="iframe-id">
    #document
      <html>
        <body contenteditable="true">
        </body>
      </html>
    </iframe>
  </body>
</html>

Selenium RC在几年前就被弃用了。建议您切换到使用Selenium WebDriver。请注意,Selenium 2提供了这两种API,因此,出于向下兼容性的考虑,如果需要,您可以进行混合和匹配

以下是如何使用WebDriver API执行此操作:

driver.switchTo().frame("iframe-id");
WebElement body = driver.findElement(By.xpath("//body"));
body.click();
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].innerHTML = 'Hello World!'", body);
driver.switchTo().frame("iframe-id");
WebElement body = driver.findElement(By.xpath("//body"));
body.click();
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].innerHTML = 'Hello World!'", body);