Nightwatch: NightWatch Test failing in Selenium Grid : Timed out while waiting for element to be present for 10000 milliseconds. - expected "visible" but got: "not found"

Created on 16 Oct 2020  ยท  10Comments  ยท  Source: nightwatchjs/nightwatch

Describe the bug

Timed out while waiting for element to be present for 10000 milliseconds. - expected "visible" but got: "not found"

Sample test

module.exports = {
'Search google': function (browser) {
โ€‹
browser
.url('http://google.co.in/')
.assert.titleContains('Google')
.assert.visible('input[name="q"]')
.sendKeys('input[name="q"]', 'nightwatch\n')
.assert.containsText('.g .rc', 'Nightwatch.js')
.end();
}
}

Run with command
npx nightwatch -e hostedGrid tests\search\google.js

Verbose output

D:\git\functional-tests\nightwatchjs-tests>npx nightwatch -e hostedGrid tests\search\google.js --verbose

[Search\google] Test Suite

  • Connecting to 10.240.8.73 on port 4444...
    Request POST http://10.240.8.73:4444 /wd/hub/session
    {
    desiredCapabilities: {
    browserName: 'chrome',
    platform: 'ANY',
    chromeOptions: { args: [ 'start-maximized' ] },
    name: 'Search\google'
    }
    | Connecting to 10.240.8.73 on port 4444...
    Response 200 POST http://10.240.8.73:4444/wd/hub/session (872ms)
    {
    value: {
    sessionId: '04aee5a2fc2cd202cb453c08108319bb',
    capabilities: {
    acceptInsecureCerts: false,
    browserName: 'chrome',
    browserVersion: '86.0.4240.75',
    chrome: {
    chromedriverVersion: '86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})',
    userDataDir: '/tmp/.com.google.Chrome.5IafuS'
    },
    'goog:chromeOptions': { debuggerAddress: 'localhost:34750' },
    networkConnectionEnabled: false,
    pageLoadStrategy: 'normal',
    platformName: 'linux',
    proxy: {},
    setWindowRect: true,
    strictFileInteractability: false,
    timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
    unhandledPromptBehavior: 'dismiss and notify',
    'webauthn:virtualAuthenticators': true,
    'webdriver.remote.sessionid': '04aee5a2fc2cd202cb453c08108319bb'
    }
    }
    i Connected to 10.240.8.73 on port 4444 (929ms).
    Using: chrome (86.0.4240.75) on linux platform.
    Received session with ID: 04aee5a2fc2cd202cb453c08108319bb
    โ†’ Running [before]:
    โ†’ Completed [before].
    Running: Search google
    โ†’ Running [beforeEach]:
    โ†’ Completed [beforeEach].
    โ†’ Running command: url ('http://google.co.in/')
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/url
    { url: 'http://google.co.in/' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/url (1534ms)
    { value: null }
    โ†’ Completed command: url ('http://google.co.in/') (1546ms)
    โ†’ Running command: assert.titleContains ('Google')
    โ†’ Running command: title ([Function])
    Request GET http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/title
    Response 200 GET http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/title (610ms)
    { value: 'Google' }
    โˆš Testing if the page title contains 'Google' (615ms)
    โ†’ Completed command: assert.titleContains ('Google') (618ms)
    โ†’ Running command: assert.visible ('input[name="q"]')
    โ†’ Completed command: title ([Function]) (616ms)
    โ†’ Running command: isVisible ('input[name="q"]', [Function])
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (613ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (611ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (612ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (621ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (611ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (608ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (612ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (615ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    Request POST http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements
    { using: 'css selector', value: 'input[name="q"]' }
    Response 200 POST http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb/elements (1627ms)
    {
    value: [
    {
    'element-6066-11e4-a52e-4f735466cecf': 'c8f93d88-8d85-40bc-8da4-2121171853cd'
    }
    ]
    }
    ร— Testing if element at Object.Search google (D:\git\functional-tests\nightwatchjs-tests\tests\search\google.js:6:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    โ†’ Completed command: isVisible ('input[name="q"]', [Function]) (10687ms)
    โ†’ Completed command: assert.visible ('input[name="q"]') (10696ms)
    โ†’ Running [afterEach]:
    โ†’ Completed [afterEach].
    FAILED: 1 assertions failed, 1 errors and 1 passed (12.866s)
    โ†’ Running [after]:
    โ†’ Completed [after].
    โ†’ Running command: end ()

    โ†’ Running command: session ('delete', [Function])
    Request DELETE http://10.240.8.73:4444 /wd/hub/session/04aee5a2fc2cd202cb453c08108319bb
    Response 200 DELETE http://10.240.8.73:4444/wd/hub/session/04aee5a2fc2cd202cb453c08108319bb (658ms)
    { value: null }
    โ†’ Completed command: end () (664ms)
    โ†’ Completed command: session ('delete', [Function]) (660ms)


TEST FAILURE: 1 error during execution; 1 assertions failed, 1 passed (14.602s)
ร— search\google
โ€“ Search google (12.866s)
Testing if element at Object.Search google (D:\git\functional-tests\nightwatchjs-tests\tests\search\google.js:6:15)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
NoSuchElementError: An error occurred while running .isVisible() command on {"value":[{"element-6066-11e4-a52e-4f735466cecf":"c8f93d88-8d85-40bc-8da4-2121171853cd"}]}
at processTicksAndRejections (internal/process/task_queues.js:97:5)

Configuration

module.exports = {
src_folders: ["tests"],
page_objects_path: ["page_objects"],
globals_path: 'globals.js',
โ€‹
test_workers: {
enabled: true,
workers: 4
},
โ€‹
test_settings: {
default: {
launch_url: 'http://google.com',
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
},
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
"window-size=1280,800"
]
}
},
},
โ€‹
hostedGrid: {
launch_url: 'http://google.com',
selenium: {
start_process: false,
port: 4444,
host: "10.240.8.73",
},
webdriver: {
start_process: false,
keep_alive: true,
timeout_options: {
timeout: 60000,
retry_attempts: 3
}
},
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
"start-maximized"
]
},
}
}
}
}
Collapse

| Executable | Version |
| ---: | :--- |
| nightwatch --version | ^1.4.3 |
| npm --version | 6.14.6 |
| node --version | V12.18.4 |
| Browser driver Chrome | 86.0.4 |

Most helpful comment

running into a similar error on nightwatch 1.5.1 when running selenium grid 3 + chrome on fargate. Ours occurs broadly for things like .waitForElementPresent('body') or .waitForElementPresent('head'). I expect its a config issue between your browser setup and nightwatch capabilities config.

FWIW- I haven't gotten it to work but my research is as follows:

referenced issue:
https://github.com/nightwatchjs/nightwatch/issues/2414

Others suggest to set chromeOptions w3c = false and args as follows:

//good explanation in readme: https://github.com/taktakpeops/selenium-grid-ecs-fargate

chromeOptions: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },

from: https://github.com/SeleniumHQ/selenium/issues/7476#issuecomment-519938952
In chromedriver 75+ you are expected to pass goog:chromeOptions as the key as chromeOptions itself is not w3c compliant. Instead if you w3c = false it is allowed chromeOptions.

Although, I attempted to pass both as received an error when passing goog:chromeOptions. It also does not appear like these settings were correctly applying to my session/ nightwatch correctly doing the config. I am still investigating but will post once I have solution.

EDITED:
was able to get it working by adding this in nightwatch.conf.js:

['goog:chromeOptions']: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },

All 10 comments

Try setting w3c: false.

We tried with w3c: false in chrome options but still getting the same error. Please note we get error in Firefox as well.

Testing if element

Issue happens in our hosted grid in open stack.

Test runs fine in locally created grid if started from nightwatch (i.e. selenium: { start_process: true, server_path: require('selenium-server').path,...}) (

@beatfactor can we please get help on this, we got stuck and can't move forward. Please check and do the needful.

@beatfactor any guidence for us will be really helpful.

@beatfactor we are facing the same issue as well. We tried using w3c:fasle as per your recommendations for chromeoptions, firefoxoptions and safarioptions and still we are having issues with basic commands like

  1. waitForElementVisible
  2. waitForElementPresent
  3. setValues
  4. click

We did some further investigation to try and pinpoint where the problem resides and our findings are shown below. This consisted of executing a simple Nightwatch script against different versions of Selenium Servers/Selenium Grids. When trying different versions of Selenium Server we saw some improvement for some of the problems that are occurring. In some cases Nightwatch interacts with some browsers better than on other versions of Selenium Server but there doesn't appear to be a version of Selenium Server that will overcome enough of the compatibility issues

Please note: We have tested the sample example shown below on both Local selenium server and also on a docker container(Linux, chrome, firefox).

Nightwatch version: 1.5.1
Example:
Sample test
module.exports = {
'Search google': function (browser) {
โ€‹
browser
.url('http://www.google.com')
.waitForElementPresent('input[name="q"]')
.waitForElementVisible('input[name="q"]')
.sendKeys('input[name="q"]', 'nightwatch')
.assert.containsText('.g .rc', 'Nightwatch.js')
.end();
}
}

Nightwatch.conf.js
chrome: {
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
w3c: false
}
}
},
firefox: {
desiredCapabilities: {
browserName: "firefox",
platformName: "MAC",
firefoxOptions: {
w3c: false
}
}
}

Outcome:

Nightwatch versionSelenium Server/Grid VersionWeb BrowserWeb Browser VersionNightwatchNotes
1.5.13.0.1Chrome87YESNo issues with the latest browser.
1.5.13.0.1Firefox83YESNo issues with the latest browser.
1.5.13.0.1Safari14.0.0YES 
1.5.13.0.1Safari14.0.1NOPost browser update, Safari 14.0.1 does not work with NightWatch 1.5.1
1.5.13.14.0Chrome87NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.14.0Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.14.0Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Chrome87NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.59 (latest stable release)Chrome87YESNo issues with the latest browser. May encounter issues when test with different versions of the same browsers
1.5.13.141.59 (latest stable release)Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.59 (latest stable release)Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.14.0.0-alpha-7 (new alpha release)Chrome87NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.
1.5.14.0.0-alpha-7 (new alpha release)Firefox83NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.
1.5.14.0.0-alpha-7 (new alpha release)Safari14.0.1NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.

Any help/guidance would be greatly appreciated

running into a similar error on nightwatch 1.5.1 when running selenium grid 3 + chrome on fargate. Ours occurs broadly for things like .waitForElementPresent('body') or .waitForElementPresent('head'). I expect its a config issue between your browser setup and nightwatch capabilities config.

FWIW- I haven't gotten it to work but my research is as follows:

referenced issue:
https://github.com/nightwatchjs/nightwatch/issues/2414

Others suggest to set chromeOptions w3c = false and args as follows:

//good explanation in readme: https://github.com/taktakpeops/selenium-grid-ecs-fargate

chromeOptions: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },

from: https://github.com/SeleniumHQ/selenium/issues/7476#issuecomment-519938952
In chromedriver 75+ you are expected to pass goog:chromeOptions as the key as chromeOptions itself is not w3c compliant. Instead if you w3c = false it is allowed chromeOptions.

Although, I attempted to pass both as received an error when passing goog:chromeOptions. It also does not appear like these settings were correctly applying to my session/ nightwatch correctly doing the config. I am still investigating but will post once I have solution.

EDITED:
was able to get it working by adding this in nightwatch.conf.js:

['goog:chromeOptions']: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },

Thanks for the follow up @leetmachine

I have some follow up questions:

  1. What selenium grid version are you using?
    Please note: we are able to run tests on chrome browser using seleniumgrid - 3.141.59, but the chrome tests fail on the latest seleniumgrid - 4.0.0-alpha-7
  2. Have you tried running your tests in firefox and safari browsers on Selenium grid?
    If so, can you share your results/any workarounds you may have considered?

@leetmachine: Your are awesome!!!

@beatfactor: Since you are a maintainer....why must w3c be set to false? The official Nightwatch.js docs claims that it uses the W3C WebDriver API .... Does it have anything to do with the usage of custom commands?
Any additional insights into the issue would help for the development of tests in the future.... We intend to use Nightwatch.js a lot and want to be as up to date and as compliant with modern standards as possible.

@rkhaneds Were you able to solve your issue with the solution introduced by @leetmachine ?

If you are using docker selenium grid you can try updating it to version 4, that solved the issue for me. Selenium grid 3 will be deprecated soon anyway. Note: If you use :latest docker will install version 3 still , you need to specify the version 4 for installation. Hope this is helpful to you too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willli666 picture willli666  ยท  3Comments

bushev picture bushev  ยท  4Comments

gary5 picture gary5  ยท  4Comments

sgleonardoopitz picture sgleonardoopitz  ยท  3Comments

MateuszJeziorski picture MateuszJeziorski  ยท  3Comments