How to Send preformatted text in Webdriver using Sendkeys...?

889 views
Skip to first unread message

neeraj bakhtani

unread,
Sep 22, 2013, 5:52:04 AM9/22/13
to webd...@googlegroups.com
Hi friends
I am trying to automate on Application
and I need to send Pre formatted text in Text box
with italics, bold and uderlined.

But I think sendkeys does not allow formatting of text.

2.Text is too large, so if i use Sendkeys it takes time to type and emulate user.
can we use Ctrl+v to copy the text directly to text box from clipboard...?

Luke Inman-Semerau

unread,
Sep 22, 2013, 9:45:18 AM9/22/13
to webd...@googlegroups.com
You'll want to use the JavaScriptexecutor executeScript to insert the large text. 

As for preformatting, that'll all depend in the rich text editor that you are using I think. I've never tried anything related to what you are hinting at doing so I'm just not sure what is possible :)

-Luke
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

darrell

unread,
Sep 22, 2013, 10:19:57 AM9/22/13
to webd...@googlegroups.com
If the website is using UTF-8 then sendKeys is going to send UFT-8 characters. If it is using Latin-1 (ISO-8859-1) then it is only going to send ISO-8859-1 characters. The concept of bold, italics and underline is not part of the character set. It is part of the application. If I am sending raw HTML then bold on is the three characters <B> and bold off is the four characters </B>. On the other hand, if I am editing a wiki page in Confluence editor I set something to bold by surrounding it by *. For example, if I use webElement.sendKeys("*Bold*") to a Confluence editor it will appear as bold in the preview and once saved.

So concepts like bold, italic and underline will be completely dependent on the editor your website is using.

As for sendKeys being slow. This is true. For large amounts of text it will be quite slow. When I input text into a text field there could be events associated with the text field. If you inject things into it with javascript or use CTRL-V (on a Windows machine) it could bypass the events and have a different effect. Even when I am testing manually, using the keyboard versus pasting the text in will often have different results if the website is javascript rich. This is something to consider when deciding how to handle this situation.

If you decide to use the clipboard and paste the text in you have to realize you cannot switch to RemoteWebDriver or the Grid. The tests and the web browser have to be on the local machine. Additionally, CTRL-V does not work on a Mac. So you might have issue with how cut and paste works on the current machine. If all you are testing on is Windows computers it is not an issue.

If you use javascript injection, as Luke suggests, then it will be as fast as CTRL-V but it will work over RemoteWebDriver and on all operating systems.

You still need to figure out what characters to send in order to make your application display bold, underline, italics.
Reply all
Reply to author
Forward
0 new messages