Search This Blog

Breaking

Wednesday, 5 August 2020

Slow down the speed of typing in selenium Type/SendKeys/setValue method

Recently, I faced an issue in our current automation where when we were typing string value through selenium webdriverIo setValue method, then after a few words, the cursor jumps to the beginning of the document. This was clearly the issue with the customized froala editor we were using in the application. But I was not able to replicate it manually. 

So to fix this issue, I will need to slow down the speed of typing in the editor. And this speed was coming from the "setValue()" method from webdriverIO API. 

My sample Text was :

const value = "Auto- This note is created from automation at 09-05-2020 12:48 PM"

$(selector).setValue(value)

It was typing something like this in UI field:

 9-05-20is created from automAuto-This note tion at 020 12:48 PM

Which was completely a garage statement.

So to fix this issue, I changed my approach of typing. While earlier I was using setValue() method where I was passing the complete string.

Now, Instead of this, I passed each character of the string to keys() method and put a pause in between those character passing.

So the code now changed to:

const value = "Auto- This note is created from automation at 09-05-2020 12:48 PM"
const arrValue = [...value]; // This is for converting string to charArray

for(let i = 0 ; i< arrValue.length; i++) {
browser.keys(arrValue[i] );
browser.pause(200); // .5 milisecond pause
}

Output: Auto- This note is created from automation at 09-05-2020 12:48 PM

Now I got the desired output, little slow but correctly.

Note: The framework is built with webdriverIo and Typescript. But this approach can be used in any selenium based framework. 

#UIAutomation #SetValue


No comments:

Post a Comment