!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: Getting Selected Text  (Read 1743 times)

Christian Hargraves

  • Web User
Getting Selected Text
« on: February 21, 2012, 03:25:26 PM »
I was wondering if there is a way to get text selected by a mouse in the
 browser. For example, maybe a user has several paragraphs presented to her
 and she is supposed to select the misspelled text and change it. Is there a
 way to select text and also capture the text that is selected?
 
Thanks,
 Christian

Offline Ana Stavreva

  • Sr. Member
  • ****
  • Posts: 253
Re: Getting Selected Text
« Reply #1 on: February 21, 2012, 03:25:41 PM »
Hi Christian,
 At the moment, there's no API for doing either of those tasks. I
 suppose that if there was, it would look a little like:
 
String selectText(int startIndex, int length);
 
Being slightly negative: the drawback with this method is that you
 could well fall foul of browser quirks, particularly if attempting to
 select text from something that is not a text field or area (as in, a
 chunk of text from the body of the page) Although we try and mask the
 differences in rendering engines between browsers when you call
 "getText", it's not perfect. I suspect the same problems would make
 implementing the "selectText" method hard work too.
 
Being slightly positive: I can see why people would like this
 functionality, and perhaps having warning and caveats around it might
 make things easier, particularly if we limit what elements this method
 could be used with.
 
What does everyone else think?
 
Regards,
 
Simon
 

- Show quoted text -

Christian Hargraves

  • Web User
Re: Getting Selected Text
« Reply #2 on: February 21, 2012, 03:25:49 PM »
Hi Simon,
 
I think this feature would be useful for people who might want to use
 WebDriver outside of the realm of testing. Or maybe to help create a tool
 that aids testers in writing automated tests. To accomplish something like
 that getSelectedText would be most useful.
 
Thanks for the quick reply,
 Christian
 On Wed, Oct 22, 2008 at 8:51 PM, Simon Stewart <simon.m.stew...@gmail.com>wrote:
 

- Show quoted text -

Selenium Webdriver

Re: Getting Selected Text
« Reply #2 on: February 21, 2012, 03:25:49 PM »

Marc Guillemot

  • Web User
Re: Getting Selected Text
« Reply #3 on: February 21, 2012, 03:25:59 PM »
Simon,
 text selection makes sense not only on text field and areas. If you want
 to add an API to select text and read selected text (what I would
 welcome), the solution you propose is too simplistic. Indeed I believe
 that you will have to do something like what the traversal range API [1]
 does and have something like:
 
String selectText(WebElement startContainer, int startOffset, WebElement
 endContainer, int endOffset);
 
the simple method
 String selectText(int startIndex, int length);
 may nevertheless be interesting on a WebElement as shortcut for
 selecting text within a single node.
 
Cheers,
 Marc.
 --
 Web: http://www.efficient-webtesting.com
 Blog: http://mguillem.wordpress.com
 
[1] http://www.w3.org/TR/DOM-Level-2-Traversal-Range/
 

- Show quoted text -

Michael Tamm

  • Web User
Re: Getting Selected Text
« Reply #4 on: February 21, 2012, 03:26:08 PM »
Hi,
 
I like the philosopy "Do only one thing, but do it perfect".
 
WebDriver is library for automated testing.
 
If I weight the difficulty in implementing a select whatever method
 (and without that, a get selected whatever method is pointless)
 against the benefit of having such a functionality (for what kind
 of tests?) I would say this is a very low priority issue at best.
 
Greetings, Michael
 
2008/10/23 Marc Guillemot <mguille...@yahoo.fr>
 

- Show quoted text -

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
1013 Views
Last post May 02, 2012, 08:10:43 PM
by Ambika Rajagopalan
0 Replies
685 Views
Last post June 15, 2012, 03:00:42 AM
by kaushal247
6 Replies
1074 Views
Last post July 04, 2012, 04:22:37 PM
by Rovin
3 Replies
1359 Views
Last post July 25, 2012, 03:34:01 PM
by dlai
6 Replies
2691 Views
Last post January 07, 2013, 09:30:52 PM
by smani
1 Replies
571 Views
Last post June 19, 2013, 09:18:05 PM
by prassad
1 Replies
298 Views
Last post August 12, 2013, 11:12:30 PM
by Andrew_