1

I am developing Spectron UI tests using Mocha for application that runs on Electron. The main issue that I have is that Javascript does not threat texts inputs by tool equally to real inputs from the keyboard.

As workaround for that I want to apply blur event on particular field after value for it is set. The problem here is that 'element' method of WebdriverIO is returning JSON object and not the DOM element, so .on("blur") cannot be chained to it.

Any suggestions how this can be achieved?

Thanks in advance.

  • A code snippet would have helped in understanding your issue more in depth. And more proposed solutions can be expected. Share what you are getting as JSON and how are you are utilising it ? – T Gurung Mar 20 '18 at 15:27
  • element method of WebdirverIO returns that: { ELEMENT: '0.5501418109949332-1', 'element-6066-11e4-a52e-4f735466cecf': '0.5501418109949332-1' }, selector: '#name' } – Stoyko Stoykov Mar 21 '18 at 08:53
  • I want workaround of how can I get the DOM element and not that JSON file. – Stoyko Stoykov Mar 21 '18 at 08:54

1 Answers1

3

I know this has been posted a long time ago, but I just found this post while looking up how to achieve the same thing. I'll post the method I used to achieve this in case anyone else needs something similar.

In the meantime I've concluded that there is no way to directly achieve this through available webdriver.io functions but can be done alternatively through the browser.execute method.

To be able to easily reuse this I've created a function which makes use of the browser.execute functionality, and then called it wherever I needed to trigger the blur.

function triggerBlur(elementSelector){
    browser.execute((selector) => {
        document.querySelector(selector).blur();
    }, elementSelector);//pass the selector to the execute function
}

    
//example usage

let targetElementSelector = '#myInput',

targetElement = browser.$(targetElementSelector);

targetElement.setValue("new value");

triggerBlur(targetElementSelector);