How to get and set the value of a text editor in selenium

I have a text editor on a web page, I need to fill in its value using selenium scripts in C #. I know how to do this for a text box. I checked the process from Set value in a text box , but when I tried the same process for a text editor, it does not work, I want to get and set the value of the editor. please help me how can i do this.

to get the text of the text field:

IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");

I tried the code below to set the editor value

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>");
+4
source share
3 answers

:

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
        js.ExecuteScript("document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument.getElementsByClassName('cke_editable_themed')[0].innerHTML='dfjkbgdk';");

.....

+1

, CKEditor.

: WYSIWYG Selenium WebDriver

- , . , Firefox. PhantomJS Chrome. , <span>hiiiiiiii<span> , span.

  • innerHTML
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);
  • API CKEditor
var executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("CKEDITOR.instances.ckeditor.setData('<span>hiiiiiiii<span>");
+7
IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = Driver.FindElement(By.Id("passwordTextBox"));
passwordTextBox.Clear();
passwordTextBox.SendKeys("password");

IWebElement passwordTextBox = firefoxDriver.FindElement(By.Id("passwordTextBox"));

Also checking the id of the element you are looking for By.Id("passwordTextBox")is the correct other wise use of xpath / css

+4
source

Source: https://habr.com/ru/post/1538950/


All Articles