admin管理员组文章数量:1435799
I have a web page that I am trying to test via Webdriver I/O. My question is, how do I click a couple of links via a test? Currently, I have the following:
var webdriverio = require('webdriverio');
var client = webdriverio.remote(settings).init()
.url('')
.elements('a')
.then(function(links) {
for (var i=0; i<links.value.length; i++) {
console.log('Clicking link...');
var link = links.value[i].ELEMENT;
link.click().then(function(result) {
console.log('Link clicked!');
});
}
})
;
When the above gets executed, I get an error that says "click is not a function" on link. When I print link
to the console, it looks like JSON, which would make sense since the documentation says that the elements function returns WebElement JSON objects. Still, I'm just trying to figure out how to click this link.
How does one do such?
Thanks!
I have a web page that I am trying to test via Webdriver I/O. My question is, how do I click a couple of links via a test? Currently, I have the following:
var webdriverio = require('webdriverio');
var client = webdriverio.remote(settings).init()
.url('http://www.example.')
.elements('a')
.then(function(links) {
for (var i=0; i<links.value.length; i++) {
console.log('Clicking link...');
var link = links.value[i].ELEMENT;
link.click().then(function(result) {
console.log('Link clicked!');
});
}
})
;
When the above gets executed, I get an error that says "click is not a function" on link. When I print link
to the console, it looks like JSON, which would make sense since the documentation says that the elements function returns WebElement JSON objects. Still, I'm just trying to figure out how to click this link.
How does one do such?
Thanks!
Share Improve this question edited Feb 13, 2016 at 20:36 Marty Aghajanyan 13.4k8 gold badges36 silver badges37 bronze badges asked Jan 2, 2016 at 18:36 JQuery MobileJQuery Mobile 6,30124 gold badges88 silver badges138 bronze badges 3-
What about find your element by selector and
click
method?client.click('a', function(err,res) {...})
– Valijon Commented Jan 4, 2016 at 19:58 - @Valijon That approach will only click the first link. It will not click each link. – JQuery Mobile Commented Jan 5, 2016 at 1:02
-
If you need to click couple links with "purpose", set
class
orid
attributes for that links. Then, via selectors"#some_id", "a.some_class"
click them. In our project, we use Selenium for Java, and we do click objectively, like login, logout, main page, second page, etc... – Valijon Commented Jan 5, 2016 at 9:35
2 Answers
Reset to default 5 +100You need elementIdClick
http://webdriver.io/api/protocol/elementIdClick.html
Here is an example
var settings = {
desiredCapabilities: {
browserName: 'firefox',
},
};
var webdriverio = require('webdriverio');
var client = webdriverio.remote(settings).init()
.url('http://www.example.')
.elements('a')
.then(function(links) {
for (var i=0; i<links.value.length; i++) {
console.log('Clicking link...');
var link = links.value[i].ELEMENT;
client.elementIdClick(link).then(function(result) {
console.log('Link clicked!');
});
}
});
Result of the above code will be
Clicking link...
Link clicked!
Hello there you could do directly this though: it clicks all elements a on the page
var client = webdriverio.remote(settings).init()
.url('http://www.example.')
.click('a')
.end()
);
you could you a selector to target specific a elements example:
.click("article .search-result .abstract .more")
本文标签: javascriptClicking links with WebdriverIOStack Overflow
版权声明:本文标题:javascript - Clicking links with WebdriverIO - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745624872a2666912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论