Javascript Selenium(JS)中WebElement的getText()失败

Javascript Selenium(JS)中WebElement的getText()失败,javascript,selenium,selenium-webdriver,Javascript,Selenium,Selenium Webdriver,我在尝试使用JavaScript selenium webdriver从WebElement提取纯文本时遇到了一个问题。我目前使用的是MicrosoftEdge浏览器和驱动程序,所有的设置都是正确的,但我不明白为什么在JavaScript Selenium中尝试从WebElement获取值会被破坏。例如,假设以下文档: <html> <body> <p>Hello</p> <a href="http:/

我在尝试使用JavaScript selenium webdriver从WebElement提取纯文本时遇到了一个问题。我目前使用的是MicrosoftEdge浏览器和驱动程序,所有的设置都是正确的,但我不明白为什么在JavaScript Selenium中尝试从WebElement获取值会被破坏。例如,假设以下文档:

<html>
    <body>
        <p>Hello</p>
        <a href="http://bing.com/maps" class="myClass">Maps</a>
    </body>
</html>
任何不直接与元素交互的操作(例如sendKeys或click),包括
isDisplayed()
之类的调用,似乎都会失败,并在控制台中给出一些异常跟踪。我在Windows 10上使用selenium webdrivier 3.3.0,版本为6.10.0


为方便起见。

getText和getAttribute返回使用请求的值解析的承诺

elm.getText().then(function (text) {
   console.log(text);
});

getText和getAttribute返回使用请求的值解析的承诺

elm.getText().then(function (text) {
   console.log(text);
});

在我的公寓工作:

await teste.driver.findElement({
    css: 'input[name="nameElementExample"]'
  }).getAttribute("value");

在我的公寓工作:

await teste.driver.findElement({
    css: 'input[name="nameElementExample"]'
  }).getAttribute("value");