Reputation: 11
I use mocha, webdriverio selenium-standalone framework. I want to Click element using JavaScriptExecutor,but doesn't work.
Can anybody help me?
Thanks
it('click icon',function(){
browser.waitForVisible(elementselector.dockServiceButton, 2000);
assert.ok(browser.isExisting(elementselector.dockServiceButton));
dockServiceButtonElement=$('//div[@class="icon-dock icon-dock-service "]')
JavaScriptExecutor ex = (JavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", dockServiceButtonElement);
}
Upvotes: 1
Views: 4364
Reputation: 344
I had the same problem, made it work using:
// clicks on element using JavaScript
browser.addCommand("jsClick", function(this: ElementResult) {
this.then((element) => {
browser.execute("arguments[0].click();", element.value);
});
});
This code is also working
browser.addCommand("jsClick", function(this: any) {
browser.execute("arguments[0].click();", this.element().value);
});
More about addCommand: http://webdriver.io/api/utility/addCommand.html
Upvotes: 2
Reputation: 1887
You can't use javascript executor for this. You already do proper click in test 'login system', so just use the same:
browser.click(dockServiceButtonElement);
// or you can call click method directly on element object:
dockServiceButtonElement.click()
Source: http://webdriver.io/api/action/click.html
Upvotes: 0