Total Pageviews

Friday, 24 July 2020

Input Values Using JavaScript


if there is no value attribute in DOM for element the use
((JavascriptExecutor) getDriver()).executeScript("arguments[0].innerHTML='YOUR-VALUE-IN-SINGLEQUOT'",driver.findElement(By.xpath("//input[@id='xdc']")));


if there is value attribute defined in DOM then use
((JavascriptExecutor) getDriver()).executeScript("arguments[0].value='YOUR-VALUE-IN-SINGLEQUOT'",driver.findElement(By.xpath("//input[@id='xdc']")));

Sometimes in some applications .. like the application which are based on extJS framework the dom changes after performing some actions . For example




Here we see for the cell DOM looks as highlighted .

If  we double click on it to enable it then the DOM changes like ..


But using automation if we locate this element and try to send keys using selenium then it will throw selenium exception -- Element Not Intractable

That's one of the pain with extJS application while automating using selenium which occurs sometimes.

Now if you will right click on cell and select inspect




You will find a new element has been introduced in DOM to input values which earlier was not present.




So to insert value in scenarios like this you will fill first have to perform double click and then locate the element which appears later and send keys to it.





No comments:

Post a Comment