简体   繁体   中英

How to extract text using action class in selenium webdriver?

I have written code to copy text using action class of selenium webdriver. All I have been able to do is to drag cursor around the text and copy it.

Code snippet :

Actions a = action.clickAndHold(element)
                        .moveToElement(element1)
                        .release()
                        .keyDown(Keys.CONTROL)
                    .sendKeys("c")
                        .keyUp(Keys.CONTROL);
a.perform();

Now how do I print this text on display console using java?

You should really just use WebElement#getText() . If you need to get the text of several elements, simply concatenate it. It will be much easier, much more reliable and it will work on every browser and OS.

But since you asked:

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
System.out.println(clipboard.getData(DataFlavor.stringFlavor));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM