我正在使用簡單的NodeJS腳本來測試google.com。使用phantomJS瀏覽器。錯誤消息:無法在phantomsJS中找到xpath的元素
var webdriver = require('selenium-webdriver');
var assert = require('assert');
var driver = new webdriver.Builder().
withCapabilities({
browserName : "phantomjs"
}).
usingServer('http://127.0.0.1:4444/wd/hub').build();
//driver.manage().timeouts().implicitlyWait(60000);
driver.get('http://www.google.com');
driver.findElement(webdriver.By.xpath('//*[@id="gbqf"]')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.getTitle().then(function(title) {
assert.equal("webdriver - Google Search", title);
});
driver.quit();
運行使用
> java -jar selenium-server-standalone-2.35.0.jar
運行腳本使用並行命令node
獨立硒服務器。
我收到以下錯誤
> timers.js:103
> if (!process.listeners('uncaughtException').length) throw e;
> ^UnknownError: Error Message => 'Unable to find element with xpath
> '//*[@id="gbqf"]'' caused by Request =>
> {"headers":{"Accept":"application/json,
> image/png","Connection":"Keep-Alive","Content-Length":"45","Content-Type":"application/json;
> charset=utf-8","Host":"localhost:17476"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//*[@id=\\\"gbqf\\\"]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/440b8b90-0fc8-11e3-8024-5bdaea20ab82/element"}
> Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12
> 15:42:01' System info: os.name: 'Linux', os.arch: 'i386', os.version:
> '2.6.18-8.el5', java.version: '1.6.0_16' Driver info: driver.version:
我使用Ruby綁定硒..它工作 –
@Babai HTML是相同的[http://google.co.in](http://google.co.in) –