Select / highlight text
See original GitHub issueCurrent behavior:
I’m having a hard time creating a text selection. Things I’ve tried:
document.createRange()andwindow.getSelection()- Using
cy.triggerto simulate a cursor drag over the paragraph. - Using
dblclickon the paragraph.
Desired behavior:
Test highlighting text.

Steps to reproduce:
I can provide sample code for the approaches I tried, but I’ll hold off for now in case there’s a completely different known way of doing this.
Versions
Cypress 3.1.1, Chrome 70.0.3538.102
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:20 (7 by maintainers)
Top Results From Across the Web
How to select or highlight text in Windows | Digital Citizen
Highlighting text in Windows by clicking or tapping works pretty much the same way as selecting multiple items. Click or tap once, and...
Read more >Highlight your text - Microsoft Support
Select the text that you want to highlight. · On the Home tab, select the arrow next to Text Highlight Color Text highlighter...
Read more >How to select and highlight text in rich text editors | TinyMCE
In this article we have a deep dive into complex cases of text selection and highlighting in text editors and explain possible solutions....
Read more >How to get the Highlighted/Selected text in JavaScript?
There may be a need to find out the text selected/highlighted by the user. It can be done very easily using the window...
Read more >How to Apply, Remove, and Find Highlighted Text in Word
Click the arrow next to the Text Highlight Color button. Choose the color you want to use from the drop-down menu.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Here are a couple of commands that are working for my team, using Cypress to test a Slate based editor: https://gist.github.com/erquhart/37bf2d938ab594058e0572ed17d3837a
Includes the ability to naively select based on text matching:
Or set both the start and end points of the selection:
Also
setCursorBefore/Afterwith the same text matching interface, plus some other lower level commands.This would have to be a new command entirely, and isn’t planned for the native events release. However we do plan to support text selection in the future
In the meantime, you can try this: