Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.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
Java 在Selenium中找不到textarea中的元素_Java_Selenium Chromedriver - Fatal编程技术网

Java 在Selenium中找不到textarea中的元素

Java 在Selenium中找不到textarea中的元素,java,selenium-chromedriver,Java,Selenium Chromedriver,我有一个用于文本区域的html块,如下所示: <div id="block-517e9e97-d25b-41b1-8108-463e0137df8c" class="wp-block block-editor-block-list__block has-selected-ui" data-block="517e9e97-d25b-41b1-8108-463e0137df8c" data-type="core/paragr

我有一个用于文本区域的html块,如下所示:

<div id="block-517e9e97-d25b-41b1-8108-463e0137df8c" class="wp-block block-editor-block-list__block has-selected-ui" data-block="517e9e97-d25b-41b1-8108-463e0137df8c" data-type="core/paragraph" tabindex="0" aria-label="Block: Paragraph" role="group" style="" xpath="1">
    <p role="textbox" aria-multiline="true" aria-label="Empty block; start writing or type forward slash to choose a block" style="" class="rich-text block-editor-rich-text__editable wp-block-paragraph" contenteditable="true">
        <span data-rich-text-placeholder="Start writing or type / to choose a block" contenteditable="false">
        </span>
    </p>
</div>

<p role="textbox" aria-multiline="true" aria-label="Empty block; start writing or type forward slash to choose a block" style="" class="rich-text block-editor-rich-text__editable wp-block-paragraph" xpath="1" contenteditable="true">
    <span data-rich-text-placeholder="Start writing or type / to choose a block" contenteditable="false">
    </span>
</p>

这是因为在xpath中,您已使用“”两次,因此退出了字符串:

而不是:
“//*[@id=“block-517e9e97-d25b-41b1-8108-463e0137df8c”]”

尝试使用:
“/*[@id='block-517e9e97-d25b-41b1-8108-463e0137df8c']”


使用“for the xpath”和“for the id name”

这是因为在xpath中您已经使用了两次“”并因此退出了字符串:

而不是:
“//*[@id=“block-517e9e97-d25b-41b1-8108-463e0137df8c”]”

尝试使用:
“/*[@id='block-517e9e97-d25b-41b1-8108-463e0137df8c']”

使用“for the xpath”和“for”作为id名称

driver.findElement(By.id(“block-517e9e97-d25b-41b1-8108-463e0137df8c”)。发送键(“文本”)

当您检查web元素时,如果您有按id标识元素,则首先使用该id并执行操作,因为id是唯一的,如果您没有id,则只转到Xpathdriver.findElement(按.id(“block-517e9e97-d25b-41b1-8108-463e0137df8c”)。sendKeys(“text”)

当您检查web元素时,如果您有按id标识元素,则首先使用该id并执行操作,因为id是唯一的,如果您没有id,则只转到Xpath

driver.findElement(By.xpath("//*[@id="block-517e9e97-d25b-41b1-8108-463e0137df8c"]")).sendKeys("This is text area");