Javascript executor uses

   Javascriptexecutor js=((javascriptexecutor)driver);

    js.executescript("window.scrollBy(1000));******* to scroll horizontally
    js.executescript("scroll(1000));   ***********to scroll
    js.executescript("alert("i am ravi");");********* alert message
    js.executescript("history.go(0)"); ************** to clear history
    js.executescript("document.getelementbyid("").value("");");**********sendkeys
    js.executescript("document.getelementbyid("").click();");
    js.executescript("return document.title;").to string();
    js.executescript("return document.url;").tostring();
    js.executescript("window.location="------------"");");
     js.executescript(("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 2px solid yellow;"););


reusable code for highlighteleemnt
 public static void flash(WebElement element, WebDriver driver) {
        JavascriptExecutor js = ((JavascriptExecutor) driver);
        String bgcolor  = element.getCssValue("backgroundColor");
        for (int i = 0; i <  3; i++) {
            changeColor("rgb(0,200,0)", element, js);
            changeColor(bgcolor, element, js);
        }
    }
    public static void changeColor(String color, WebElement element,  JavascriptExecutor js) {
        js.executeScript("arguments[0].style.backgroundColor = '"+color+"'",  element);

        try {
            Thread.sleep(20);
        }  catch (InterruptedException e) {
        }
     }

Comments

Popular posts from this blog

Selenium Locators usage

Java Theory interview questions

java programmes frequently asked in interview