Reputation: 31
I'm working with Webdriverio, Selenium and Javascript
In my frontend, I have three divs each containing a table with same classname (field_table). The divs has id 0, 1 and 2 and same classname (receiver_field)
Every table contains a button with the same classname as well (delete-button).
That is because the tables are automaticly generated
In my Webdriverio Selenium test, I would like to click one of the tree buttons, so that I can delete one entry
But how do I navigate to only one button when they all have the same classnames? I tried navigate via the id but I can't get it to work
it('should be possible to delete on button click', function () {
// Get receiver fields
var fields = browser.elements('.form-control-list');
expect(fields.value.length).to.equal(6);
// Get only one table
// Get that tables button
// Click the button
//expect(fields.value.length).to.equal(4);
});
Any suggestions?
Upvotes: 1
Views: 546
Reputation: 1736
In general, you need to get all the elements with the same class name into a list (or array), and then select the element you want to interact with from the list.
Eg.:
Elems = browser.findElementsByClassName("class_name")
Elems[0].click()
Adapt the above to JavaScript, I'm not that good with it. :)
Upvotes: 1