1

I'm trying to run a simple test with selenium without success.

I have a javascript config test:

chrome.config.js

var driver = new webdriver.Builder().
  .forBrowser('chrome')
  .build();


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

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

I'm getting the following error:

(node:5921) UnhandledPromiseRejectionWarning: WebDriverError: element not interactable (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64) at Object.checkLegacyResponse (/home/pablo/workspace/bricks-editor/node_modules/selenium-webdriver/lib/error.js:585:15) at parseHttpResponse (/home/pablo/workspace/bricks-editor/node_modules/selenium-webdriver/lib/http.js:533:13) at Executor.execute (/home/pablo/workspace/bricks-editor/node_modules/selenium-webdriver/lib/http.js:468:26) at at process._tickCallback (internal/process/next_tick.js:188:7) (node:5921) 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(). (rejection id: 1) (node:5921) [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.

What can be wrong here?

My settings:

node version: 8.11.3

chromedriver version: 2.44.609551

OS: Ubuntu 18.0.4 LTS 64 bits

2 Answers 2

1

After some tests, I was able to do my code work with the following changes.

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

var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .build();


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

var btnI;

driver.findElements(By.name('btnI')).then(function(list) {
  btnI = list[1];
  btnI.click();
});
Sign up to request clarification or add additional context in comments.

Comments

1

There are two input fields with the same @name: the first one is hidden. You need to handle the second (visible) one:

driver.findElement(By.cssSelector('div.FPdoLc input[name="btnI"]')).click();

5 Comments

Hi Anderson, with the first option, I'm getting Cannot read property 'click' of undefined
@PabloDarde , try driver.findElement(By.cssSelector('div.FPdoLc input[name="btnI"]')).click();
Hi Anderson. I didn't get the submit method works as well. Thanks anyway.
@PabloDarde , Sorry, I'm not familiar with Selenium JavaScript binding. I've just converted Python code into JavaScript. Didn't expect simple code implementation to be so complicated in JavaScript :)
No problems @Andersson, you gave me the tip of findElements. Thanks man

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.