3

Estou usando o windows, usando o node.js com o selenium para fazer automação de um site. meu problema e que eles esta dando erro na função click().

Código abaixo e o que vem de exemplo ja pronto quando digita npm install selenium-webdriver.

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

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

driver.get('http://www.google.com/ncr')
    .then(_ =>
        driver.findElement(By.name('q')).sendKeys('wiki'))
    .then(_ =>
        driver.findElement(By.name('btnK')).click())
    .then(_ => driver.wait(check_title, 1000));

function check_title() {
    var promise = driver.getTitle().then(function (title) {
        if (title === 'wiki - Google Search') {
            console.log('success');
            return true;
        } else {
            console.log('fail -- ' + title);
        }
    })
    return promise;
}

Segue agora o erro que me retornou...

    DevTools listening on ws://127.0.0.1:54874/devtools/browser/78c2868b-41a2-4d72-8da9-95f6a3fd05ec //Aqui ele abriu o navegador e escreveu no bampo de busca.
(node:924) UnhandledPromiseRejectionWarning: WebDriverError: element not interactable // aqui ele deu erro na parte do click() e saiu dando erro no resto...
  (Session info: chrome=73.0.3683.75)
  (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT
10.0.17134 x86_64)
    at Object.checkLegacyResponse (D:\Automacao site - Selenium\node_modules\selenium-webdriver\lib\error.js:585:15)
    at parseHttpResponse (D:\Automacao site - Selenium\node_modules\selenium-webdriver\lib\http.js:533:13)
    at Executor.execute (D:\Automacao site - Selenium\node_modules\selenium-webdriver\lib\http.js:468:26)    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:924) 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:924) [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.
PS D:\Automacao site - Selenium>

1 Resposta 1

0

Consegui resolver usando:

const { Builder, By, Key, until } = require('selenium-webdriver');

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

driver.get('http://www.google.com/ncr')
    .then(_ =>
        driver.findElement(By.name('q')).sendKeys('wiki', Key.RETURN))
    .then(_ => driver.wait(check_title, 1000));

function check_title() {
    var promise = driver.getTitle().then(function (title) {
        if (title === 'wiki - Google Search') {
            console.log('success');
            return true;
        } else {
            console.log('fail -- ' + title);
        }
    })
    return promise;
}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .