简体   繁体   中英

How can i get xpath count in selenium webdriver using jasmine javascript?

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

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');

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

browser.getXpathCount("//somenode");

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;
  ...
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM