I have text Editor on a web page, i need to fill its value using selenium scripting in c#. I know how to do it for textbox. i have checked the process from Set value in textbox but when i have tried the same process for text editor, it is not working, i want to get and set the value of editor. please help me how can i do this.
code for getting text of textbox is :
IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");
I have tried the below code to set value of editor
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>");
We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.
We can get a selected option in a dropdown in Selenium webdriver. The method getFirstSelectedOption() returns the selected option in the dropdown. Once the option is fetched we can apply getText() method to fetch the text.
The getText() method returns the visible inner text of a web element.
IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");
In above code change 2nd line to
IWebElement passwordTextBox = firefoxDriver.FindElement(By.Id("passwordTextBox"));
Also check id of element you are searching By.Id("passwordTextBox")
is correct other wise use xpath/css
Looks like you are trying send keys to CKEditor.
Please read through this article: Test WYSIWYG editors using Selenium WebDriver
This approach is the one you have tried and didn't work. It's known to have issues with Firefox. Your code should work for PhantomJS or Chrome. Note that <span>hiiiiiiii<span>
will result in actual text in the editor, not a span element.
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);
var executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("CKEDITOR.instances.ckeditor.setData('<span>hiiiiiiii<span>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With