0

I'm getting started with Selenium using Javascript. I tried the following code:

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

const driver = new webdriver.Builder().forBrowser("chrome").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();
  });
});

I am getting the following error:

$ node google_test

DevTools listening on ws://127.0.0.1:60706/devtools/browser/74ff1ebf-908a-4f60-973c-95507cade998 Test failed (node:2796) UnhandledPromiseRejectionWarning: ElementNotInteractableError: element not interactable (Session info: chrome=87.0.4280.66) at Object.throwDecodedError (C:\Users\x\selenium-test\node_modules\selenium-webdriver\lib\error.js:550:15) at parseHttpResponse (C:\Users\x\selenium-test\node_modules\selenium-webdriver\lib\http.js:565:13) at Executor.execute (C:\Users\x\selenium-test\node_modules\selenium-webdriver\lib\http.js:491:26) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async thenableWebDriverProxy.execute (C:\Users\x\selenium-test\node_modules\selenium-webdriver\lib\webdriver.js:700:17) (Use node --trace-warnings ... to show where the warning was created) (node:2796) 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:2796) [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.

When I use this code, it kind of works, but I get different error:

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

const driver = new webdriver.Builder().forBrowser("chrome").build();

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

var query = driver.wait(until.elementLocated(By.name("q")));
query.sendKeys("webdriver\n");

driver.wait(until.titleContains("webdriver - Google"));

The error:

$ [12612:12448:1202/120322.598:ERROR:usb_descriptors.cc(160)] Device descriptor parsing error. [12612:12448:1202/120322.599:ERROR:device_event_log_impl.cc(211)] [12:03:22.599] USB: usb_device_win.cc:93 Failed to read descriptors from \?\usb#vid_413c&pid_2113#70000030#{a5dcbf10-6530-11d2-901f-00c04fb951ed}. [12612:12448:1202/120322.600:ERROR:device_event_log_impl.cc(211)] [12:03:22.600] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) [12612:12448:1202/120322.607:ERROR:usb_descriptors.cc(160)] Device descriptor parsing error. [12612:12448:1202/120322.608:ERROR:device_event_log_impl.cc(211)] [12:03:22.608] USB: usb_device_win.cc:93 Failed to read descriptors from \?\usb#vid_0424&pid_2807&asmediausbd_hub#00000830#{a5dcbf10-6530-11d2-901f-00c04fb951ed}. [12612:12448:1202/120322.620:ERROR:usb_descriptors.cc(160)] Device descriptor parsing error. [12612:12448:1202/120322.621:ERROR:device_event_log_impl.cc(211)] [12:03:22.621] USB: usb_device_win.cc:93 Failed to read descriptors from \?\usb#vid_0bda&pid_8153#000001000000#{a5dcbf10-6530-11d2-901f-00c04fb951ed}. [12612:12448:1202/120322.623:ERROR:device_event_log_impl.cc(211)] [12:03:22.623] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

Please help me understand what's going wrong?

user3132457
  • 789
  • 2
  • 11
  • 29
  • As per https://stackoverflow.com/a/65081791/5324105 you can ignore the second error log. May be it will be turned off in next release – Rahul L Dec 02 '20 at 11:33
  • ok i will use the 2nd code, but how do i `quit()` afterwards? i get another error when i add `driver.quit()`? – user3132457 Dec 02 '20 at 12:23
  • Refer https://help.crossbrowsertesting.com/selenium-testing/getting-started/javascript/ You will need to understand async /await in Javascript – Rahul L Dec 02 '20 at 12:28
  • thanks for the link, i was able to run the script for chrome, but it fails for firefox, looks like enter is not pressed and the page title is the old one: https://hastebin.com/igevicepaw.js – user3132457 Dec 02 '20 at 14:31

0 Answers0