I am testing a web application project using Protractor . The few test cases which I have written is running fine but I am getting difficulties when I try to count the number of div elements present inside a parent div element, The structure of my div is given below
<div class="page-kontact-main">
<div class="buttons contact_page">
<a href="http://mysite.se/om-oss/" class="btn btn-default button">Om oss</a>
<a href="http://mysite.se/offert-3/" class="btn btn-default button">Offert</a>
<a href="http://mysite.se/tjanster/" class="btn btn-default button">Våra Tjänster</a>
</div>
<div class="row kontact-title">
<h2>Våra medarbetare</h2>
<p>
Test desc <span class="s47jd228h2" id="s47jd228h2_5">med</span> passion och engagemang för it & system. Skicka in din ansöka
</p>
<p> </p>
</div>
<div class="row clearfix">
<div class="col206"></div>
<div class="col206"></div>
<div class="col206"></div>
<div class="col206"></div>
<div class="col206"> </div>
<div class="col206"></div>
<div class="col206"></div>
<div class="col206"> </div>
</div>
</div>
And I have written the test case like this as given below but it is not running the error is expected undefined to equal 21.
it('Getting the count of contact names ', function() {
driver.get("http://mysite.se/kontakt/");
var element = driver.findElement(protractor.By.css('.clearfix .col206'));
expect(element.length).toEqual(21);
});
Thanks Utpal
You should use element.all and count() instead of length:
it('Getting the count of contact names ', function() {
driver.get("http://mysite.se/kontakt/");
var elements = element.all(protractor.By.css('.clearfix .col206'));
expect(elements.count()).toEqual(21);
});
$
and $$
are equivalent to element.all
and by.css
, so you can use the following code
it('Getting the count of contact names ', function() {
driver.get("http://mysite.se/kontakt/");
var elements = $$('.clearfix .col206'));
expect(elements.count()).toEqual(21);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With