I'm trying to use Nodejs + selenium-webdriver + mocha to do some web-based automation. But when I use HTMLUnit to run the test, By.xpath() always report NoSuchElement error, even though the element is really there. Same code can work well with FireFox and other browsers.
I found a same issue reported to selenium https://code.google.com/p/selenium/issues/detail?id=6419, and it's doing the same thing with what I do, but only in Java.
Here is a sample for this problem.
// Sample code provided by selenium-webdriver
// http://selenium.googlecode.com/git/docs/api/javascript/index.html
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
// withCapabilities(webdriver.Capabilities.htmlunit()).
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver.get('http://www.google.com/ncr');
// Can be accessed successfully
//driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
// Element can't be found by HTMLUnit, but works fine with FF
driver.findElement(webdriver.By.xpath('//*[@id="gbqfq"]')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
More information about my environment:
Nodejs : v0.10.22
selenium-webdriver module: 1.3.14
selenium-webdriver server jar: selenium-server-standalone-2.40.0.jar
Sorry not sure about the correct HTMLUnit version I'm using, since it's included in the selenium-webdriver component. I picked 2.40 because it's the same with the selenium I'm using...
Yang,
please provide a simple testcase (http://htmlunit.sourceforge.net/submittingJSBugs.html). If you can show the problem with a simple Html page, we will try to fix this.
This simple java code works with the latest code from svn (when simulation FF17, FF24 and IE11)
This is of course java code, but keep in mind that the HtmlUnit development team is small and we can not support all languages and tools working on top of HtmlUnit.
Additionally i have added another test to our test suit, that also shows that this xpath works.
Will close this issue. If you still have a problem, please try to extract a simple testcase.
am also facing the same issue with Htmlunit driver,but same code/xpath is working in Chrome driver. can somebody please help to resolve the issue.