我目前正在使用pylen的selenium绑定,并希望评估JavaScript绑定,但我仍然坚持使用示例应用程序! 我似乎无法理解,在这个例子中有什么不对,任何帮助都会受到赞赏。
我的package.json文件如下所示:
{
"name": "selenium_tests",
"version": "0.0.0",
"repository": {},
"devDependencies": {
"mocha": "^1.21.4",
"selenium-webdriver": "^2.43.5"
}
}
我的脚本如下所示:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function () {
'use strict';
return driver.getTitle().then(function (title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
运行时的错误堆栈如下:
D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1745
throw error;
^
Error: Wait timed out after 1039ms
at D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1412:29
at D:\selenium_node\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
at webdriver.promise.ControlFlow.runInNewFrame_ (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1640:20)
at notify (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:444:12)
at then (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:497:7)
at Object.webdriver.promise.asap (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:749:11)
at newFrame.then.e (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1656:25)
at D:\selenium_node\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
at webdriver.promise.ControlFlow.runInNewFrame_ (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1640:20)
at notify (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:444:12)
==== async task ====
at webdriver.promise.ControlFlow.wait (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\promise.js:1397:15)
at webdriver.WebDriver.wait (D:\selenium_node\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:589:21)
at Object.<anonymous> (D:\selenium_node\original_sample.js:12:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
答案 0 :(得分:2)
在支持硒的友好人士的帮助下,我解开了谜团,我只是愚蠢。 由于www.google.com会根据您的IP地址的位置自动重定向,因此我已登陆本地化的Google网页,标题不再是“网络驱动程序 - Google搜索”。
只使用正确的本地化标题或阻止谷歌使用
进行本地化driver.get('http://www.google.com/ncr');
解决了这个问题。