catherine
catherine

Reputation: 11

how to use JavascriptExecutor in mocha webdriverio

enter image description here enter image description here I use mocha, webdriverio selenium-standalone framework. I want to Click element using JavaScriptExecutor,but doesn't work.

Can anybody help me?

Thanks

enter image description here

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

Answers (2)

Anton Kumpan
Anton Kumpan

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

Tomas
Tomas

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

Related Questions