As yous know, Every spider web chemical division has Its ain meridian in addition to width or nosotros tin tell size of element. Sometimes yous quest to perform pixel to pixel testing equally per client's requirement similar each in addition to every button's meridian should endure x(some pixels) in addition to width should endure y(some pixels) through out the site.
Now If yous become for measuring meridian in addition to width of every element manually therefore It Is fourth dimension consuming on every seek out cycle. Automation Is best solution to mensurate meridian in addition to width of elements because It Is i fourth dimension practise in addition to therefore yous tin purpose It In every seek out cycle.
Now If yous become for measuring meridian in addition to width of every element manually therefore It Is fourth dimension consuming on every seek out cycle. Automation Is best solution to mensurate meridian in addition to width of elements because It Is i fourth dimension practise in addition to therefore yous tin purpose It In every seek out cycle.
We convey learnt how to acquire x y coordinates of chemical division using selenium webdriver In previous post. Now permit us larn how to acquire size of element. I convey prepared elementary event to explicate yous how to acquire meridian in addition to width of Image In selenium webdriver. As yous tin come across In bellow example, I convey used getSize() method to acquire meridian in addition to width of element.
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; world course of report getElementSize { WebDriver driver; @BeforeTest world void setup() throws Exception { driver =new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(" "); } @Test world void getSize() throws Exception { //Locate chemical division for which yous wants to acquire meridian in addition to width. WebElement Image = driver.findElement(By.xpath("//img[@border='0']")); //Get width of element. int ImageWidth = Image.getSize().getWidth(); System.out.println("Image width Is "+ImageWidth+" pixels"); //Get meridian of element. int ImageHeight = Image.getSize().getHeight(); System.out.println("Image meridian Is "+ImageHeight+" pixels"); } }
When yous run inwards a higher house seek out In eclipse, It volition impress meridian in addition to width of chemical division In console equally bellow.
Image width Is 212 pixels Image meridian Is 191 pixels
We tin use Height And Width Of Element to capture element's screenshot equally described In THIS POST.
This agency yous tin detect whatsoever element's size In selenium test.
http://www.software-testing-tutorials-automation.com/