【问题标题】:C# Selenium Webdriver (Firefox) iFrame does not allow text to be entered via sendKeysC# Selenium Webdriver (Firefox) iFrame 不允许通过 sendKeys 输入文本
【发布时间】:2016-04-07 10:56:34
【问题描述】:

我正在使用最新的 Selenium Firefox (2.53.0) 以前的代码在执行以下操作时可以正常工作

1) 通过Xpath iframe 类查找iFrame

IWebElement detailFrame =      `Driver_Lib.Instance.FindElement(By.XPath("//iframe[@class='cke_wysiwyg_frame cke_reset']"));`

2) 通过

切换到该帧
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);

3) 通过

在 iFrame 中找到 p 标签
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("p"));

4) 向 iframe 文本框插入一个简单的字符串

freeText.SendKeys("this is some text");

5) 从 iFrame 切换回主内容窗口

Driver_Lib.Instance.SwitchTo().DefaultContent();

这是应用程序的代码部分

<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor" aria-describedby="cke_61" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title data-cke-title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor">Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor</title>
<style data-cke-temp="1">
<link href="https://myUrl/contents.css" rel="stylesheet" type="text/css">
<style data-cke-temp="1">
</head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="false">
<p>

<br _moz_editor_bogus_node="TRUE">
</p>
</body>
</html>
</iframe>

我正在运行的测试是一个简单的测试,打开那个页面,插入一些文本,保存。

它不会将文本插入 iFrame。我完全不知道为什么。

还有其他人发现这个问题吗?

非常感谢

我已经删除了异常,这是一个红鲱鱼。

iFrame 不能输入文本

【问题讨论】:

  • 你有什么例外吗?
  • 异常中的定位器与示例中的定位器不匹配。请更新您的问题。
  • 列出的例外是一条红鲱鱼,所以我已将其删除。为什么它抛出这个异常是这样的:1)iFrame 不能输入文本。 2) 输入文本后单击下一步按钮。 3) 应用程序的验证表明 iFrame 文本是强制性的,但是我们现在在一个新页面上,抛出的异常与页面中应该允许保存的 buttonID 有关。该错误与无法在 iFrame 中输入文本有关。

标签: selenium iframe


【解决方案1】:

大家好,我找到了解决方案:~ 这是发生的事情的摘要:

1) xPath 正在定位 iFrame。

2) 使用的 SwitchTo() 方法将焦点放在 IWebElement 的 detailFrame 实例中

3) 没有发生的是 p 标记无法定位,因为它包含在 CSS 主体类中。

解决方案一直盯着我看!这么简单!!

我这样做了:

IWebElement detailFrame = Driver_Lib.Instance.FindElement(By.XPath("//iframe[@class='cke_wysiwyg_frame cke_reset']"));         

           Driver_Lib.Instance.SwitchTo().Frame(detailFrame);

           IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("body"));             


           freeText.SendKeys("This is a free text question created by Automation Smoke Test");

            Driver_Lib.Instance.SwitchTo().DefaultContent(); 

如您所见,只需找到body标签的第一个实例!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2014-10-24
    • 2013-01-11
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多