1
var sample1 = browser.findElements(driver.By.xpath('//somenode')).getXpathCount();
console.log( sample1.intValue() );

while printing the count I am getting error:

error occuredTypeError: undefined is not a function

3 Answers 3

1

Like @alecxe stated, the syntax for getXpathCount() is browser.getXpathCount("//somenode").

I saw you opened an issue on the selenium git and had more code there. What isn't showing here is you have just the following.

var browser = require('selenium-webdriver');
var sample1 = browser.findElements(driver.By.xpath('//somenode')).getXpathCount();
console.log( sample1.intValue() );

I haven't used WebDriverJs, so someone please correct me if I am wrong, but I think you need to create a browser object. Right now you only have created a driver object named browser.

Can you try the following snippet?

var webdriver = require('selenium-webdriver');
var browser = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();

browser.get('http://en.wikipedia.org/wiki/Wiki');
browser.getXpathCount('//*[@id="www-wikipedia-org"]/div[1]/div');
Sign up to request clarification or add additional context in comments.

1 Comment

yeah i tried this I am still getting the same error.Anyway by using elements.length as stated below answer i am able to find the count
0

findElements method returns an Array promise, so you have to do something like this:

browser.findElements(driver.By.xpath('//somenode')).then(function(elements) {
  var count = elements.length;
  ...
})

Comments

0

I think you are not using getXpathCount() correctly. You should do it this way:

browser.getXpathCount("//somenode");

1 Comment

yeah i tried with this, but still getting "error occuredTypeError: undefined is not a function"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.