Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 textarea-在Javascript中-解释_Javascript_Selenium_Selenium Webdriver_Selenium Chromedriver_Selenium Ide - Fatal编程技术网

Selenium textarea-在Javascript中-解释

Selenium textarea-在Javascript中-解释,javascript,selenium,selenium-webdriver,selenium-chromedriver,selenium-ide,Javascript,Selenium,Selenium Webdriver,Selenium Chromedriver,Selenium Ide,我有一段html,它位于下拉列表下,在下拉列表元素中选择somthing后显示: <div class="mx-0 w-100 row"> <textarea id="notes" placeholder="Write here..." required="" class="form-control"> </textarea> </div>

我有一段html,它位于下拉列表下,在下拉列表元素中选择somthing后显示:

<div class="mx-0 w-100 row">
    <textarea id="notes" placeholder="Write here..." required="" class="form-control"> </textarea>
</div>
现在,如果不是我用的第一行

const notes = await driver.wait(until.elementLocated(By.id('notes')), delay)

显然,用
notes
替换
notes[0]
,它给了我

ElementNotInteractableError: element not interactable
问题是:为什么会发生这种情况?我不太喜欢选择带有数字的数组元素,但实际上我不得不这样做,我不明白为什么其他选择器不工作。

这行代码

const notes = await driver.wait(until.elementsLocated(By.css('textarea')), delay)
…works as notes是由.css('textarea')标识为
的所有元素的列表,这会导致
elementsLocated()
出现一定的延迟,幸运的是,第一个匹配元素,即
notes[0]
是您所需的元素,您已经完成了

显然,使用
By.id('notes')
By.xpath('/*[@id=“notes”]')
的第一个匹配元素不是您想要的元素


解决方案 最好的解决方案是按如下方式制作更精细的:

  • css:

  • xpath:


在第二种和第三种情况下,您是否仍在等待元素可见?是的,相同的代码!尝试使用
const notes=wait driver.wait(直到.elementIsVisible(By.id('notes')),delay)
Wow,非常感谢,我对selenium是新手(我一周前开始使用),但我完全没有弄明白这一点。尽管如此,我们仍然不太清楚为什么使用
By.id('notes')
的第一个匹配元素没有返回正确的元素,我的意思是,它是一个id,应该是唯一的@Diego在所需元素的顶部有其他元素,其属性为
id
notes
,不可见,因此不是您所需的元素。
ElementNotInteractableError: element not interactable
const notes = await driver.wait(until.elementsLocated(By.css('textarea')), delay)
const notes = await driver.wait(until.elementLocated(By.css("textarea.form-control#notes")), delay)
const notes = await driver.wait(until.elementLocated(By.xpath("//textarea[@class='form-control' and @id='notes']")), delay)