Nightwatch: Expect.element.text.to.equal is not working in ChromeDriver

Created on 3 Jan 2017  路  7Comments  路  Source: nightwatchjs/nightwatch

Hi,

I have an error when I use the Expect.element.text.to.equal or Expect.element.text.to.contain in the ChromeDriver.

This is my test:

      .navigate()
      .waitForElementVisible('body', 1000);

project.expect.element('title').text.to.equal('Project title');

(project is my pageObject)

This test pass if I run the test with the GeckoDriver.

But with the ChromeDriver I have the following error:
Expected element <title> text to equal: "Project title" - expected "equal 'Project title'" but got: ""

I use [email protected]

Have you ever encountered this error?

Most helpful comment

Same issue.
Using nightwatch v. 0.9.14, node.js v7.7.4, macOS v10.12.4, Selenium Server Standalone 3.3.1 on Java 8, ChromeDriver

Test code is:

module.exports = {
'step one': function(browser) {
browser
.url('https://www.pintux.it')
.waitForElementVisible('body', 5000);
browser.expect.element('title').to.be.present;
browser.expect.element('title').text.to.equal("Antonio Pintus' Home Page");
},

'step two': function(browser) {
browser
.click('a[href="http://jaranto.blospot.com"]')
.pause(5000);
browser.expect.element('title').to.be.present;
browser.expect.element('title').text.to.equal("a.p");
browser.end();
}
};

Error is:

  • step one (4.662s)
    Expected element text to equal: "Antonio Pintus' Home Page" - expected "equal 'Antonio Pintus' Home Page'" but got: ""</li> </ul> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/4560610?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt=" picture"> <strong>pintux</strong> <span class="text-muted ml-1">on 28 Mar 2017</span> </div> <div class="col text-right"> 👍<span class="ml-2 mr-3">4</span> </div> </div> </div> </div> </div> <div class="col-12"> <div class="mb-4"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3835332123789605" data-ad-slot="9295564578" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="col-12 d-flex align-items-center mb-4"> <h2>All 7 comments</h2> </div> <div class="col-12"> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Try using this custom Nightwatch command to achieve what you want:<br /> <a rel="nofollow noopener" target="_blank" href="https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/es6/commands/waitForTitle.js">https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/es6/commands/waitForTitle.js</a></p> <p>or, the transpiled version...<br /> <a rel="nofollow noopener" target="_blank" href="https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/js/commands/waitForTitle.js">https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/js/commands/waitForTitle.js</a></p> <p>View the rest of the project here:<br /> <a rel="nofollow noopener" target="_blank" href="https://github.com/maxgalbu/nightwatch-custom-commands-assertions">https://github.com/maxgalbu/nightwatch-custom-commands-assertions</a></p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/20962?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="fc picture"> <strong>fc</strong> <span class="text-muted ml-1">on 5 Jan 2017</span> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Never had any issues with the expect syntax</p> <blockquote> <p>project.expect.element('title').text.to.equal('Project title');</p> </blockquote> <p>Did you tried to use the <code>@</code> notation for your page-object elements ?</p> <p>regards<br /> ~david</p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/291518?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="davidlinse picture"> <strong>davidlinse</strong> <span class="text-muted ml-1">on 8 Mar 2017</span> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Same issue.<br /> Using nightwatch v. 0.9.14, node.js v7.7.4, macOS v10.12.4, Selenium Server Standalone 3.3.1 on Java 8, ChromeDriver</p> <p>Test code is:</p> <p>module.exports = {<br /> 'step one': function(browser) {<br /> browser<br /> .url('https://www.pintux.it')<br /> .waitForElementVisible('body', 5000);<br /> browser.expect.element('title').to.be.present;<br /> browser.expect.element('title').text.to.equal("Antonio Pintus' Home Page");<br /> },</p> <p>'step two': function(browser) {<br /> browser<br /> .click('a[href="http://jaranto.blospot.com"]')<br /> .pause(5000);<br /> browser.expect.element('title').to.be.present;<br /> browser.expect.element('title').text.to.equal("a.p");<br /> browser.end();<br /> }<br /> };</p> <p>Error is:</p> <ul> <li>step one (4.662s)<br /> Expected element <title> text to equal: "Antonio Pintus' Home Page" - expected "equal 'Antonio Pintus' Home Page'" but got: ""</li> </ul> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/4560610?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="pintux picture"> <strong>pintux</strong> <span class="text-muted ml-1">on 28 Mar 2017</span> </div> <div class="col text-right"> 👍<span class="ml-2 mr-3">4</span> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Same issue for me. Any solution??</p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/6883041?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="didaquis picture"> <strong>didaquis</strong> <span class="text-muted ml-1">on 6 Jun 2018</span> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Same issue, any updates?</p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/20601623?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="gptt916 picture"> <strong>gptt916</strong> <span class="text-muted ml-1">on 5 Sep 2018</span> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Also facing this issue... </p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/2209844?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="meirotstein picture"> <strong>meirotstein</strong> <span class="text-muted ml-1">on 12 Nov 2018</span> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown"> <p>Hi @beatfactor. Maybe you want reopen this issue? </p> </div> <div class="card-footer"> <div class="row"> <div class="col"> <img src="https://avatars.githubusercontent.com/u/6883041?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="didaquis picture"> <strong>didaquis</strong> <span class="text-muted ml-1">on 13 Nov 2018</span> </div> <div class="col text-right"> </div> </div> </div> </div> </div> <div class="col-12"> <div class="card card-custom mb-4"> <div class="card-body pt-3 pb-3 markdown text-center helpful"> <div class="title">Was this page helpful?</div> <div class="mt-1" onMouseLeave="rating(198507895, 0);"> <i class="fas fa-star inactive" id="star-1" onMouseOver="rating(198507895, 1);" onclick="rate(198507895, 1);"></i> <i class="fas fa-star inactive" id="star-2" onMouseOver="rating(198507895, 2);" onclick="rate(198507895, 2);"></i> <i class="fas fa-star inactive" id="star-3" onMouseOver="rating(198507895, 3);" onclick="rate(198507895, 3);"></i> <i class="fas fa-star inactive" id="star-4" onMouseOver="rating(198507895, 4);" onclick="rate(198507895, 4);"></i> <i class="fas fa-star inactive" id="star-5" onMouseOver="rating(198507895, 5);" onclick="rate(198507895, 5);"></i> </div> <div class="description text-small"><span id="rating-val">0</span> / 5 - <span id="rating-count">0</span> ratings</div> </div> </div> <div class="mb-4"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3835332123789605" data-ad-slot="3452512275" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> </div> <div class="col-12 col-lg-4"> <div id="ph-above-related"></div> <div class="card card-custom issue-box"> <div class="card-body pt-3 pb-5"> <h2 class="mb-4">Related issues</h2> <div> <strong> <a href="/nightwatch/271758141/page-commands-return-typeerror-this-xx-is-not-a-function">Page commands return TypeError: this.xx is not a function regardless of what function is called</a> </strong> </div> <div class="text-muted text-small mt-2"> <img src="https://avatars.githubusercontent.com/u/19287971?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="jvlaar picture"> <strong class="pr-1" dir="ltr">jvlaar</strong>  路  <span class="px-1" dir="ltr">4</span><span>Comments</span> </div> <hr /> <div> <strong> <a href="/nightwatch/83334684/how-to-configure-nightwatch-with-expressjs-app">How to configure nightwatch with expressjs app</a> </strong> </div> <div class="text-muted text-small mt-2"> <img src="https://avatars.githubusercontent.com/u/661958?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="lgaticaq picture"> <strong class="pr-1" dir="ltr">lgaticaq</strong>  路  <span class="px-1" dir="ltr">3</span><span>Comments</span> </div> <hr /> <div> <strong> <a href="/nightwatch/154908433/error-on-assertion-fail">Error on assertion fail</a> </strong> </div> <div class="text-muted text-small mt-2"> <img src="https://avatars.githubusercontent.com/u/231649?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="manjero picture"> <strong class="pr-1" dir="ltr">manjero</strong>  路  <span class="px-1" dir="ltr">4</span><span>Comments</span> </div> <hr /> <div> <strong> <a href="/nightwatch/221954830/there-should-be-a-way-to-say-assert-true-or-false">There should be a way to say "Assert(true or false)"</a> </strong> </div> <div class="text-muted text-small mt-2"> <img src="https://avatars.githubusercontent.com/u/629396?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="aking1012 picture"> <strong class="pr-1" dir="ltr">aking1012</strong>  路  <span class="px-1" dir="ltr">4</span><span>Comments</span> </div> <hr /> <div> <strong> <a href="/nightwatch/80499874/not-skip-teststeps-after-assertion-fails">Not skip TestSteps after assertion fails</a> </strong> </div> <div class="text-muted text-small mt-2"> <img src="https://avatars.githubusercontent.com/u/7179977?v=4&s=40" style="width:20px; height:20px;" class="mr-2 rounded float-left" alt="MateuszJeziorski picture"> <strong class="pr-1" dir="ltr">MateuszJeziorski</strong>  路  <span class="px-1" dir="ltr">3</span><span>Comments</span> </div> </div> </div> <div class="sticky-top pt-4"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3835332123789605" data-ad-slot="3919948963" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div id="ph-below-related-2" class="mt-4"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3835332123789605" data-ad-slot="3919948963" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> <div class="col-12 col-lg-4"> </div> </div> <div class="skyscraper-container"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3835332123789605" data-ad-slot="7879185320" data-ad-format="vertical" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="mt-5 spacer"></div> <footer class="mt-5 pb-2 py-4 text-center mt-auto"> <div class="container"> <a class="navbar-brand logo mr-5" href="/"> <img src="/assets/img/logo.svg" width="40" height="40" alt="bleepingcoder logo"> bleeping<strong>coder</strong> </a> <div class="mt-4"> bleepingcoder.com uses publicly licensed GitHub information to provide developers around the world with solutions to their problems. We are not affiliated with GitHub, Inc. or with any developers who use GitHub for their projects. We do not host any of the videos or images on our servers. All rights belong to their respective owners. </div> <div> Source for this page: <a href="https://www.github.com/nightwatchjs/nightwatch/issues/1330" rel="nofollow noreferrer" target="_blank">Source</a> </div> </div> <hr class="mb-5 mt-5"> <div class="container"> <div class="row"> <div class="col-sm-4 col-lg mb-sm-0 mb-5"> <strong>Popular programming languages</strong> <ul class="list-unstyled mb-0 mt-2"> <li class="mb-2"> <a href="/python" dir="ltr">Python</a> </li> <li class="mb-2"> <a href="/javascript" dir="ltr">JavaScript</a> </li> <li class="mb-2"> <a href="/typescript" dir="ltr">TypeScript</a> </li> <li class="mb-2"> <a href="/cpp" dir="ltr">C++</a> </li> <li class="mb-2"> <a href="/csharp" dir="ltr">C#</a> </li> </ul> </div> <div class="col-sm-4 col-lg mb-sm-0 mb-5"> <strong>Popular GitHub projects</strong> <ul class="list-unstyled mb-0 mt-2"> <li class="mb-2"> <a href="/microsoft/vscode" dir="ltr">vscode</a> </li> <li class="mb-2"> <a href="/numpy/numpy" dir="ltr">numpy</a> </li> <li class="mb-2"> <a href="/ant-design/ant-design" dir="ltr">ant-design</a> </li> <li class="mb-2"> <a href="/mui-org/material-ui" dir="ltr">material-ui</a> </li> <li class="mb-2"> <a href="/vercel/next-js" dir="ltr">next.js</a> </li> </ul> </div> <div class="col-sm-4 col-lg mb-0"> <strong>More GitHub projects</strong> <ul class="list-unstyled mb-0 mt-2"> <li class="mb-2"> <a href="/rust-lang/rust" dir="ltr">rust</a> </li> <li class="mb-2"> <a href="/moment/moment" dir="ltr">moment</a> </li> <li class="mb-2"> <a href="/yarnpkg/yarn" dir="ltr">yarn</a> </li> <li class="mb-2"> <a href="/mozilla/pdf-js" dir="ltr">pdf.js</a> </li> <li class="mb-2"> <a href="/JuliaLang/julia" dir="ltr">julia</a> </li> </ul> </div> </div> </div> <hr class="mb-5 mt-5"> <div class="container text-muted"> 漏 2026 bleepingcoder.com - <a href="/bleeps" rel="nofollow">Contact</a><br /> By using our site, you acknowledge that you have read and understand our <a href="/cookies" rel="nofollow">Cookie Policy</a> and <a href="/privacy" rel="nofollow">Privacy Policy</a>. </div> </footer> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script> <script async src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> <!--<script defer type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5fb2db66acbd74b2"></script>--> <script type="text/javascript" src="/assets/js/main.js"></script> <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script></body> </html> <script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>