0
votes

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

2

2 Answers

0
votes

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!

-1
votes

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?