【问题标题】:How to type into a iframe in selenium RC?如何在 selenium RC 中输入 iframe?
【发布时间】:2014-07-25 11:08:13
【问题描述】:

html页面结构如下:

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

我想在 contenteditable 正文中键入一些文本。

我尝试使用下面的代码,但无法填充可编辑区域。

selenium.selectFrame("//*[@id='iframe-id']");
selenium.type("//[@contenteditable='true']", "some text");

【问题讨论】:

    标签: java iframe selenium types selenium-rc


    【解决方案1】:

    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);
    

    【讨论】:

      猜你喜欢
      • 2012-04-11
      • 2011-07-15
      • 2018-04-19
      • 2010-12-02
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多