Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择字符串并使用Selenium Java双击_Java_Javascript_Selenium_Selenium Webdriver - Fatal编程技术网

选择字符串并使用Selenium Java双击

选择字符串并使用Selenium Java双击,java,javascript,selenium,selenium-webdriver,Java,Javascript,Selenium,Selenium Webdriver,我有一个禁用的文本框,带有以下标签: <div id="writingactivityId2" class="boxSize ng-pristine ng-untouched ng-valid ng-valid-required redactor_editor writingActivityDisabled" ng-focus="editing()" redactor="" readonly="" ng-model="workInProgress.wip" required="" con

我有一个禁用的文本框,带有以下标签:

<div 
id="writingactivityId2" class="boxSize ng-pristine ng-untouched ng-valid ng-valid-required redactor_editor writingActivityDisabled" ng-focus="editing()" redactor="" readonly="" ng-model="workInProgress.wip" required="" contenteditable="false" dir="ltr" style="height: 300px;">
</div>

它有一个孩子:

<p>
Automated Test 04/03/2015 15:03:43
</p>

自动测试2015年3月4日15:03:43

有谁能建议如何选择文本“自动”或双击/单选文本“自动”吗


我试图将webElement指向
div
p
当我试图双击它时,它会选择整个页面,而不是选择文本。

您可以使用CSS选择器访问该元素,例如:


对于不同的操作系统,答案会有所不同。对于win,它将类似于:

WebElement textElement = driver.findElement(By.cssSelector("div#writingactivityId2 p"));
Actions action = new Actions(driver);
action.click(textElement).sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();

嗨,我试过了。我试图将驱动程序指向webElement div和P。当我尝试双击时,它会选择整个页面,而不是选择页面内的文本。我只想选择“自动”文本/字符串。@SPatchamatla好的,你的最终目标是什么?为什么要双击p元素?谢谢。我的目标是突出显示/选择文本“自动”。当我选择文本时,我们的应用程序将启用一个选项,可以在文本顶部进行编辑。@SPatchamatla感谢您提供的信息。您可以尝试单击或双击
div#writingactivityId2
元素吗?我并不认为
p
元素是“可操作的”。谢谢你的回复。我使用CSS选择器单击了div#writingactivityId2,它选择了整个页面,因为div#writingactivityId2是禁用的文本区域。感谢Stanger,我使用了action.moveToElement(webElement,10,10)。sendKeys(Keys.CONTROL)。click().perform();这起作用了。因为它是一个禁用的文本区域,使用Ctr+a将选择整个页面。上述措施奏效了。
WebElement textElement = driver.findElement(By.cssSelector("div#writingactivityId2 p"));
Actions action = new Actions(driver);
action.click(textElement).sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();