How to perform copy and paste

Hi

In my application I need to copy a text from an editable field and then paste it in a String.

The issue is the text is not visible in HTML so I am not able to get the text using getText() method also

Here is the screenshot of my application

How to perform copy and paste


Here I want to copy the admission number..
How to do that ?

Train Asked on November 24, 2014 in Selenium WebDriver.

Hi Som
I guess Keystrokes Should Work here You Can try WIth That

on November 24, 2014.

Hi AnkitI have no idea about  Keystrokes. Could you please help me out here. its really urgentI just used this commands directly in code 

driver.findElement(By.name("admissionNo")).sendKeys(Keys.CONTROL + "a"); Thread.sleep(2000); driver.findElement(By.name("admissionNo")).sendKeys(Keys.CONTROL + "c");
Could you please explain with some examples 

on November 24, 2014.

Paste a Screenshot of that ELemnt’s Html

on November 24, 2014.

Here is the screenshot of the HTML

How to perform copy and paste

on November 25, 2014.
Add Comment
  • 1 Answer(s)

    I would have used JavaScript in this scenario

    Supporter Answered on November 25, 2014.

    Hi Kapil

    Could you please point out on some examples to help me understand better

    on November 25, 2014.

    JavascriptExecutor jse =(JavascriptExecutor)driver;WebElement hiddenElement = driver.findElement(By.css(xxxxx....);String text = (String)(jse.executeScript("return arguments[0].text",hiddenElement));there can be some syntax error please help yourself in fixing them , as I have not tested but this would work for sure

    on November 26, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.