简体   繁体   English

如何使用Selenium Webdriver中的操作类提取文本?

[英]How to extract text using action class in selenium webdriver?

I have written code to copy text using action class of selenium webdriver. 我已经编写了代码来使用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? 现在如何使用Java在显示控制台上打印此文本?

You should really just use WebElement#getText() . 您实际上应该只使用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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何<nobr>使用 selenium webdriver</nobr>提取里面的动态文本<nobr>?</nobr> - How to extract the dynamic text inside <nobr> using selenium webdriver? 无法使用 Selenium WebDriver 中的 gettext 提取文本,也无法单击它 - Unable to extract the text using gettext in Selenium WebDriver and also unable to click it 如何通过 Java 使用 Selenium Webdriver 从下拉列表中提取 firstselectedoption 的文本 - How to extract the text of the firstselectedoption from a dropdown using Selenium Webdriver through Java 如何使用Selenium WebDriver从变量中提取文本? - How can I extract the text from a variable with Selenium WebDriver? 使用Selenium Webdriver如何检索日期文本 - Using Selenium Webdriver how to retrive date text 使用Robot类和Selenium WebDriver将大写文本发送到文本框 - Send caps text to a text box using Robot class & Selenium WebDriver 如何使用Selenium Webdriver和Java提取元素的显示属性 - How to extract the display attribute of an element using Selenium Webdriver and Java 使用 selenium WebDriver 提取文本和 web 链接 - Extract text and web links with the selenium WebDriver 使用 java/selenium webdriver 操作类引发的 InvocationTargetException - InvocationTargetException thrown with java/selenium webdriver action class 动作类在Selenium Webdriver中以调试模式工作 - Action class works in debug mode in selenium webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM