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")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745624872a4636747.html
评论列表(0条)