带NodeJS的Selenium-webdriver:ElementNotInteractableError:元素<input ...>无法滚动到视图中

时间:2020-10-22 08:04:42

标签: node.js selenium-webdriver

我才刚刚开始学习硒测试。我正在浏览Selenium Webdriver的MDN页面,尤其是此示例:

const webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

const driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('http://www.google.com');

driver.findElement(By.name('q')).sendKeys('webdriver');

driver.sleep(1000).then(function() {
  driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});

driver.findElement(By.name('btnK')).click();

driver.sleep(2000).then(function() {
  driver.getTitle().then(function(title) {
    if(title === 'webdriver - Google Search') {
      console.log('Test passed');
    } else {
      console.log('Test failed');
    }
    driver.quit();
  });
});

我已经安装了chromedriver,修改了路径文件,并激活了chromedriver。

使用脚本“节点测试”(名为test.js的文件)​​时,出现此错误:

Test failed
(node:66489) UnhandledPromiseRejectionWarning: ElementNotInteractableError: Element <input class="gNO89b" name="btnK" type="submit"> could not be scrolled into view
    at Object.throwDecodedError (/Users/matthewshields/Documents/Code/selenium/node_modules/selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/Users/matthewshields/Documents/Code/selenium/node_modules/selenium-webdriver/lib/http.js:565:13)
    at Executor.execute (/Users/matthewshields/Documents/Code/selenium/node_modules/selenium-webdriver/lib/http.js:491:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async thenableWebDriverProxy.execute (/Users/matthewshields/Documents/Code/selenium/node_modules/selenium-webdriver/lib/webdriver.js:700:17)
(node:66489) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:66489) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我已经知道,一般而言,webdriver可以正常工作,因为它可以在另一个网站上的较小示例中工作。

我还检查了页面,发现了名为“ btnK”的元素-它是“ Google搜索”,如“开始搜索”按钮中所示。我什至可以看到在运行测试时使用Tab键选择了它(蓝色轮廓)。为什么会告诉我该项目无法滚动到视图中?

页面链接:https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Your_own_automation_environment

0 个答案:

没有答案