0

I need to select the names of the whole cast; for that, I can identify the locations of the names using the CSS locators but I don't understand how can I select that text. (This is supposed be similar to the action that we perform while holding the left-mouse-button down and dragging to our desired position)

Specifically, in my case, I am trying to copy 'Ricky Gervais' and this selector takes me to it. How can I select and copy this text?

cy.get('tbody > :nth-child(2) > :nth-child(2) > a')

enter image description here

Sarmad
  • 55
  • 7

2 Answers2

0

I've found a way that serves my purpose, thought i'd share it here for others to see in the future

         cy.get(<selector-of-the-element-that-you-want-to-copy>).then(($temp)=>{
        const txt = $temp.text()
        cy.get(<selector-of-the-field/place-where-you-want-to-paste>).type(`${txt}`+'{enter}')

Important Note

.text() is not available by default. For this, first, you need to add the following plugin

npm install cypress-commands

more information can be found at these two very useful links

https://github.com/Lakitna/cypress-commands https://github.com/Lakitna/cypress-commands/blob/develop/docs/text.md

Cheers!

Sarmad
  • 55
  • 7
-1

Selecting plain text on a webpage can be done with plain javascript: Selecting text in an element (akin to highlighting with your mouse)

Copying the current selection to clipboard also: How do I copy to the clipboard in JavaScript?

Dharman
  • 21,838
  • 18
  • 57
  • 107
Robert
  • 1,002
  • 1
  • 15
  • 32