Friday, September 13, 2019

How to check Text is Bold or not using selenium | Selenium Automation


How to check Text is Bold or not using selenium 



During testing many times, we need to check whether text is Bold or not.

In Selenium using  getCssValue() method we can get the specific property and we can check text is Bold or not.

In this post, I will check “Console Output:” text is bold or not.

 

 

 


Complete Code for getting text size using selenium:
package practise;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class TextBoldOrNot {

    static WebDriver driver;

    public static void main(String args[]) throws InterruptedException {
        //System.setProperty("webdriver.chrome.driver", "‎⁨path");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.get("https://mahantesh-hadimani.blogspot.com/2019/09/how-to-check-element-in-enabled-or-not.html");
        Thread.sleep(5000);
        WebElement text = driver.findElement(By.xpath("//*[contains(text(),'Console output:')]"));
       
       
        //Read font-weight property and print It In console.
          String fontSize = text.getCssValue("font-weight");
          System.out.println("Font color -> "+fontSize);
         
    }
}

 



No comments:

Post a Comment

If any suggestions or issue, please provide