Selenium Sendkeys contain <ul><li> tag into textarea

203 Views Asked by At

When I try to send string contain <ul><li> tag into textbox using Selenium ,new tab is opened and textarea fill by <ul> only not <li>

For example:

var body = driver.FindElement(By.XPath("//*[@id=\"cke_1_contents\"]/textarea")); // then you find the body
body.SendKeys('<ul><li>option1</li><li>option2</li></ul>')

and then textarea fill by <ul></ul> and 2 new tab are opened in Chorome!!!

A true result : fill textarea by <ul><li>option1</li><li>option2</li></ul>

but now for each li opened new tab in browser and not put in textarea

1

There are 1 best solutions below

3
Prophet On

You can do that by copying the string to clipboard and then past it with WebDriver SendKeys().
Like this:

Clipboard.SetText(myStringContainingHTML);
driver.FindElement(By.Id("myTxtBoxId")).SendKeys(OpenQA.Selenium.Keys.LeftControl + "v");

In your specific question it will be

Clipboard.SetText("<ul><li>option1</li><li>option2</li></ul>");
driver.FindElement(By.XPath("//*[@id=\"cke_1_contents\"]/textarea")).SendKeys(OpenQA.Selenium.Keys.LeftControl + "v");