webdriverio 在设置其值后抛出元素不可见错误
webdriverio throws element not visible error after settings its value
第一次尝试 nodejs 和 webdriverio。在 watir-webdriver 或 selenium-webdriver gems 中尝试时,这似乎是非常简单的东西,但这让我在 webdriverio 中感到困惑。为什么当驱动程序已经找到元素并设置值时我会收到此错误
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'firefox'
}
};
var client=webdriverio.remote(options);
client
.init()
.url('http://www.twitter.com').title(function(err, res) {
console.log('Title was: ' + res.value);
})
.isExisting('#signin-password')
.then(function(isExisting){
console.log(isExisting);
})
.setValue('#signin-password','password')
.then(function(){
console.log("password set");
})
.isExisting('#signin-email')
.then(function(isExisting){
console.log("email"+isExisting);
})
.setValue('#signin-email','username')
.then(function(){
console.log("username set");
});
我得到的错误是
Title was: Welcome to Twitter - Login or Sign up
true
RuntimeError: Element is not currently visible and so may not be interacted with
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'DTNBNAUD10806XS', ip: '10.36.179.144', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: driver.version: unknown
at elementIdValue("1", "password") - at C:\Development\node_modules\webdriverio\lib\commands\setValue.js:52:7
可能是因为该元素在网页上存在,但不可见。
而不是 isExisting,使用 isVisible。
另一个原因可能是您有多个选择器 #signin-password
找到的元素,并且找到的第一个元素不可见。我并不是说这是你的问题,但在某些情况下我遇到过这种情况。
您可以尝试使用更详细的选择器,例如 #myForm #signin-password
以确保您尝试将值设置为正确的元素。
如果您使用 isExisting,您只会在 return 中得到一个布尔值。为了增加测试的稳定性,我建议您在 DOM 仍在加载
的情况下使用 waitForExist 或 waitForVisible
第一次尝试 nodejs 和 webdriverio。在 watir-webdriver 或 selenium-webdriver gems 中尝试时,这似乎是非常简单的东西,但这让我在 webdriverio 中感到困惑。为什么当驱动程序已经找到元素并设置值时我会收到此错误
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'firefox'
}
};
var client=webdriverio.remote(options);
client
.init()
.url('http://www.twitter.com').title(function(err, res) {
console.log('Title was: ' + res.value);
})
.isExisting('#signin-password')
.then(function(isExisting){
console.log(isExisting);
})
.setValue('#signin-password','password')
.then(function(){
console.log("password set");
})
.isExisting('#signin-email')
.then(function(isExisting){
console.log("email"+isExisting);
})
.setValue('#signin-email','username')
.then(function(){
console.log("username set");
});
我得到的错误是
Title was: Welcome to Twitter - Login or Sign up
true
RuntimeError: Element is not currently visible and so may not be interacted with
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'DTNBNAUD10806XS', ip: '10.36.179.144', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: driver.version: unknown
at elementIdValue("1", "password") - at C:\Development\node_modules\webdriverio\lib\commands\setValue.js:52:7
可能是因为该元素在网页上存在,但不可见。
而不是 isExisting,使用 isVisible。
另一个原因可能是您有多个选择器 #signin-password
找到的元素,并且找到的第一个元素不可见。我并不是说这是你的问题,但在某些情况下我遇到过这种情况。
您可以尝试使用更详细的选择器,例如 #myForm #signin-password
以确保您尝试将值设置为正确的元素。
如果您使用 isExisting,您只会在 return 中得到一个布尔值。为了增加测试的稳定性,我建议您在 DOM 仍在加载
的情况下使用 waitForExist 或 waitForVisible