Sometimes yous bespeak to read font properties similar font size, font color, font family, font background color etc.. during WebDriver test illustration execution. Selenium WebDriver Is really wast API together with It has many built In methods to perform really minor little operations on spider web page. Reading font property manually Is really elementary trace using firebug equally shown In bellow given Image.
If yous wants to read inward a higher house shown font belongings In selenium webdriver hence yous tin create It using .getCssValue() Method. You tin render belongings advert (Example : font-family, font-size, font-weight, etc.) amongst .getCssValue() method to read Its value.
READ MORE TUTORIALS on selenium WebDriver.
READ MORE TUTORIALS on selenium WebDriver.
Bellow given illustration volition read values of font-size, color, font-family and text-align properties of "Example Login Page" text.
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 shape fontTest { WebDriver driver = null; @BeforeTest world void setup() throws Exception { driver = novel FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.get(" "); } @Test world void readFontProperty(){ //Locate text string chemical cistron to read It's font properties. WebElement text = driver.findElement(By.xpath("//h1[contains(.,'Example Login Page')]")); //Read font-size belongings together with impress It In console. String fontSize = text.getCssValue("font-size"); System.out.println("Font Size -> "+fontSize); //Read color belongings together with impress It In console. String fontColor = text.getCssValue("color"); System.out.println("Font Color -> "+fontColor); //Read font-family belongings together with impress It In console. String fontFamily = text.getCssValue("font-family"); System.out.println("Font Family -> "+fontFamily); //Read text-align belongings together with impress It In console. String fonttxtAlign = text.getCssValue("text-align"); System.out.println("Font Text Alignment -> "+fonttxtAlign); } }
Output of inward a higher house illustration Is equally bellow.
Font Size -> 26.4px Font Color -> rgba(102, 102, 102, 1) Font Family -> "Trebuchet MS",Trebuchet,Verdana,sans-serif Font Text Alignment -> left
You tin role .getCssValue() method to larn whatsoever other belongings value of whatsoever element.