Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Css Value Width in % - Selenium WebDriver- JUnit

I have a web page which displays a dynamic layout (generated by extjs) which is supposed to occupy 100% of the width. I am using

WebElement element = driver.findElement(By.id("ext-gen4"));

String backgroundColor = element.getCssValue("width");

But currently it is returning the width in pixel and on top that the WebDriver browser (Firefox) is not displayed in maximum mode so the value is even less. Is there any way I can get the value in %? I came to know of some GetCssProperty class but I am unable to use it properly. Any details on that? I am using Selenium WebDriver 2.23 with JUnit.

I guess there must be a way to maximize the window.

like image 490
some_other_guy Avatar asked Dec 01 '25 02:12

some_other_guy


1 Answers

As Slanec said you can maximize your window like

driver.manage().window().maximize()

Than you can create a method

private float getWidthInRelationToWindow(WebElement element){
    return ((float)element.getSize().getWidth())/
                  this.drivy.manage().window().getSize().getWidth();
}
like image 196
Franz Ebner Avatar answered Dec 04 '25 02:12

Franz Ebner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!