Ram*_*ngh 5 c# asp.net selenium editor selenium-webdriver
我在网页上有文本编辑器,我需要在c#中使用selenium脚本来填充它的值.我知道怎么做文本框.我已经从文本框中的Set值检查过程,但是当我为文本编辑器尝试了相同的过程时,它不起作用,我想获取并设置编辑器的值.请帮帮我怎样才能做到这一点.
获取文本框文本的代码是:
IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");
Run Code Online (Sandbox Code Playgroud)
我已经尝试了下面的代码来设置编辑器的值
IWebElement detailFrame = driver.FindElement(By.CssSelector("#cke_1_contents .cke_wysiwyg_frame"));
driver.SwitchTo().Frame(detailFrame);
Thread.Sleep(1000);
var body = driver.FindElement(By.TagName("body")); // then you find the body
Thread.Sleep(1000);
body.SendKeys("<span>hiiiiiiii<span>");
Run Code Online (Sandbox Code Playgroud)
看起来你正在尝试向CKEditor发送密钥.
请仔细阅读本文:使用Selenium WebDriver测试WYSIWYG编辑器
这种方法是你尝试过但不起作用的方法.众所周知,Firefox存在问题.您的代码适用于PhantomJS或Chrome.请注意,这<span>hiiiiiiii<span>将导致编辑器中的实际文本,而不是span元素.
IWebElement detailFrame = driver.FindElement(By.CssSelector("#cke_1_contents .cke_wysiwyg_frame"));
driver.SwitchTo().Frame(detailFrame);
var body = driver.FindElement(By.TagName("body")); // then you find the body
var executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("arguments[0].innerHTML = '<span>hiiiiiiii<span>'", body);
Run Code Online (Sandbox Code Playgroud)
var executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("CKEDITOR.instances.ckeditor.setData('<span>hiiiiiiii<span>");
Run Code Online (Sandbox Code Playgroud)
IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");
Run Code Online (Sandbox Code Playgroud)
在上面的代码中将第二行更改为
IWebElement passwordTextBox = firefoxDriver.FindElement(By.Id("passwordTextBox"));
Run Code Online (Sandbox Code Playgroud)
另外检查你正在搜索的元素的id By.Id("passwordTextBox")是否正确使用xpath/css
我使用以下代码来执行此操作:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument.getElementsByClassName('cke_editable_themed')[0].innerHTML='dfjkbgdk';");
Run Code Online (Sandbox Code Playgroud)
这对我来说是工作......
| 归档时间: |
|
| 查看次数: |
22805 次 |
| 最近记录: |