-3

Im trying to test a feature with automation tool, cypress. As it does not allow selection of text by default, I need to do it in JS.

I want to select a word from a sentence and do some styling with it. Example : "This is a text" . When I highlight a word 'text', the tool bar for 'B, I, U' shows up. So now I want to programettically want to highlight some text so that I can click on tool bar to do some styling of the text selected.

Any idea how to do it in javascript.

uhdam
  • 25
  • 1
  • 3
  • 1
    Please post the code you have used to try and solve this problem so that we can help you with it. – user3483203 Jan 08 '18 at 17:20
  • You may Look here on already solved answer https://stackoverflow.com/questions/985272/selecting-text-in-an-element-akin-to-highlighting-with-your-mouse – Amar Pathak Jan 08 '18 at 17:21

1 Answers1

0

I have found JS functions for bold and italics. str stands for the selected text:

str.bold();
str.italics();
Marta G.
  • 36
  • 1
  • 7
  • I want to just highlight/select the text. Bold and italics I want to do by clicking the tool bar – uhdam Jan 08 '18 at 19:06
  • I type some text in a field cy.get('.ql-editor').type('check quill text'); Now I want to select some text cy.get('.ql-editor').select('text'); // this is what I want to through javascript code and then bold it using the element in tool bar cy.get('.ql-bold').click(); – uhdam Jan 08 '18 at 19:53
  • basically I jut want to highlight some text so that that styling tool bar shows up – uhdam Jan 08 '18 at 21:29