Saturday 2 January 2016

How to use Java script Executor in selenium




Create object for Java script executor and perform click,sendkeys method like below



JavascriptExecutor js = (JavascriptExecutor) driver1;

js.executeScript("document.getElementById('submit').click();");

js.executeScript("document.getElementById('gs_h0').value='Selenium';");

js.executeScript("$('#gs_h0').keyup();");



How to change object property value by using java script executor
----------------------------------------------------------------

Conside the below code

<input type="submit" jsaction="sf.chk" name="btnK" aria-label="Google Search" value="Google Search">


Here, we want to change the "value" property value from "Google Search" to "Yahoo Search" by using java script executor as per below


Code:


WebElement element = driver1.findElement(By.name("btnK"));
js.executeScript("arguments[0].setAttribute('value', 'Yahoo Search')",element);

No comments:

Post a Comment