简体   繁体   English

如何使用Selenium WebDriver(C#或Java)在Google文档中选择单个单词

[英]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.

相关问题 在C#中使用Selenium Webdriver,如何选择要写入的文本框,然后写入? - Using Selenium Webdriver in C#, how do I select a text box to write in, then write in it? 如何使用Selenium WebDriver和C#在innerHTML中查询iFrame内的元素? - How do I query innerHTML for elements that are inside of an iFrame using Selenium WebDriver and C#? 如何使Selenium Webdriver集中精力(使用C#)? - How do I get Selenium Webdriver to focus (using c#)? 如何使用 Selenium WebDriver 和 C# 在 div 中定位按钮 - How to locate a button inside a div with using Selenium WebDriver and C# 如何在Selenium Webdriver C#中单击突出显示的选项? - How do I click on highlighted option in selenium webdriver c#? 如何使用 selenium webdriver C# 检查列表框中是否存在元素/文本 - How do I check if element/text is present in listbox using selenium webdriver C# 在 C# 中使用 Selenium WebDriver,如何访问开始和结束 div 标签之间的文本? - Using Selenium WebDriver in C#, how do I access the text between the opening and closing div tags? 使用 AutoIT 进程后,如何将 Selenium Webdriver C# 重新聚焦到窗口? - How do I refocus Selenium Webdriver C# to a window after using an AutoIT process? 我如何在C#中使用Selenium Webdriver单击图像? - how can i click on image using selenium webdriver in c#? Selenium Webdriver C#为什么我必须单击两次才能选择单选按钮 - Selenium Webdriver C# why do I have to click twice to select radio button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM