3

Can anybody help me about how to use these two functions to get value of any CSS property.

Virendra Joshi
  • 469
  • 4
  • 8
  • 25
  • What seems to be the problem? [`WebElement.getCssValue()`](http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#getCssValue%28java.lang.String%29) returns a value of the element's CSS attribute. `String bgColor = driver.findElement(By.id("myId")).getCssValue("background-color");` – Petr Janeček Jun 11 '12 at 07:26
  • 1
    http://www.whathaveyoutried.com - read these please. Context would help here. Post what you've tried, otherwise we've not got a clue what you are asking. – Arran Jun 11 '12 at 21:15
  • Thanks For ur concern Slanec and Arran Actually I wanted to check if any Label is Bold or not .For that I tried to check CSS property(font-weight: bold).But I was not able to use these funtions in eclipse(testNG) as my class is already extending one class.So Please suggest upon 1.How to use WebElement.getCssValue & WebElement.getAttribute in Eclipse(TestNG) 2.Can font verification(Bold) be done with these two Functions. – Virendra Joshi Jun 14 '12 at 06:01
  • Have a look here http://stackoverflow.com/questions/18452790/how-to-using-webdriver-selenium-to-get-the-value-of-style-element/20065390#20065390 – Anirudh Oct 27 '14 at 06:50

1 Answers1

5

If have a particular <img> tag as below

<img title="Title" alt="myTitle" src="A/B/C/xyz.png">

driver.getElement(By.tagName("img")).getAttribute("src") will get you the src attribute of this tag. Result - A/B/C/xyz.png

Similarly, you can get the values of attributes such as title, alt etc.

Similarly you can get CSS properties of any tag by using getCssValue("some propety")

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
Hari Reddy
  • 3,808
  • 4
  • 33
  • 42