Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Selenium Webdriver(Firefox)iFrame不允许通过sendKeys输入文本_Selenium_Iframe - Fatal编程技术网

C#Selenium Webdriver(Firefox)iFrame不允许通过sendKeys输入文本

C#Selenium Webdriver(Firefox)iFrame不允许通过sendKeys输入文本,selenium,iframe,Selenium,Iframe,我正在使用最新的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().Fra

我正在使用最新的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切换回主contentwindow

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>

富文本编辑器,ctl00\U ctl00\U主内容占位符\U页面内容\U mlcEditor\U CKEditor


我正在运行的测试很简单,打开该页面,插入一些文本,保存

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

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

非常感谢

我已经删除了例外情况,这是一种误导


iFrame无法在其中输入文本

嗨,我找到了解决方案:~以下是所发生情况的摘要:

1) iFrame是通过xPath定位的

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标记的第一个实例

您是否收到任何异常?异常中的定位器与示例中的定位器不匹配。请更新您的问题。列出的例外情况是一种误导,因此我已将其删除。它抛出此异常的原因是:1)iFrame无法在其中输入文本。2) 输入文本后,单击“下一步”按钮。3) 应用程序的验证表明iFrame文本是强制性的,但是我们现在在一个新页面上,抛出的异常与页面中应该允许保存的buttonID有关。该错误与无法在iFrame中输入文本有关。