[英]How do I select individual words inside a Google document using selenium webdriver (C# or Java)
I'm currently testing content within google documents using selenium webdriver. 我目前正在使用Selenium Webdriver测试google文档中的内容。 Some of my tests involve selecting individual words within a google document then performing some action against them such as bold the word or change the font type for the specific word etc. 我的一些测试涉及选择Google文档中的单个单词,然后对它们执行某些操作,例如将单词加粗或更改特定单词的字体类型等。
I would simply like to be able to select a word like this: 我只希望能够选择一个这样的词:
http://s10.postimg.org/9x3d4f1q1/image.png http://s10.postimg.org/9x3d4f1q1/image.png
And here is the code returned from the Google document: 这是从Google文档返回的代码:
http://s24.postimg.org/e4zfocy9x/image.png http://s24.postimg.org/e4zfocy9x/image.png
I have tried using send keys to send a ctrl+a command and this works for me but the problem is, I need to do a little house keeping prior to running my test by creating a document with one word inside it. 我尝试使用发送键发送ctrl + a命令,这对我有用,但问题是,在运行测试之前,我需要做一些整理工作,方法是创建一个文档,其中有一个单词。 Kind of defeats the purpose of automating this. 有点失败了实现此目的的自动化。
I have tried using substring to get specific words but then I can't perform any action on the String as it will not be a web element. 我尝试使用子字符串来获取特定的单词,但是由于它不是Web元素,因此我无法对字符串执行任何操作。
Would someone be so kind and point me in the right direction? 有人会这么友善并为我指出正确的方向吗? Thanks very much for any help. 非常感谢您的帮助。 It is much appreciated. 非常感谢。
Selenium can only manipulate WebElement 硒只能操纵WebElement
In your example you won't be able to manipulate only "is" which is a text, not a HTML node. 在您的示例中,您将无法仅操作“ is”,它是文本,而不是HTML节点。
The best you can do is selecting the <span>
: 最好的选择是<span>
:
driver.findElement(By.xpath("//span[contains(text(),'This is a paragraph')]"));
and do whatever you want with it 并随心所欲
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.