Highlight test Execution in Selenium and Also Find Coordinates of Element - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Tuesday, 6 February 2018

Highlight test Execution in Selenium and Also Find Coordinates of Element

package com.neeraj.test.neeraj;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ok {

    public static WebDriver driver = new ChromeDriver();
    public static void fnHighlightMe(WebDriver driver,WebElement element) throws InterruptedException{

        System.out.println("Highlighting");
        //Creating JavaScriptExecuter Interface
        JavascriptExecutor js = (JavascriptExecutor)driver;
        for (int i = 0; i < 3; i++) {
            //Execute javascript
            js.executeScript("arguments[0].style.border='4px groove green'", element);
            Thread.sleep(1000);
            js.executeScript("arguments[0].style.border=''", element);
        }
    }


    @Test
    public void add1() throws InterruptedException{

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

        driver.get("https://www.facebook.com");
        driver.manage().window().maximize();
        Thread.sleep(6000);

        WebElement fbLogo = driver.findElement(By.xpath("//*[contains(@class,'fb_logo')]"));
        fnHighlightMe(driver, fbLogo);

        Point point = fbLogo.getLocation();
        int xcord = point.getX();
        System.out.println("Position of the webelement from left side is "+xcord +" pixels");
        int ycord = point.getY();
        System.out.println("Position of the webelement from top side is "+ycord +" pixels");
        fbLogo.click();
    }

}

No comments:

Post a Comment