Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebElement.getCssValue & WebElement.getAttribute Usage

Tags:

selenium

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

like image 596
Virendra Joshi Avatar asked Apr 13 '26 12:04

Virendra Joshi


1 Answers

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")

like image 114
Hari Reddy Avatar answered Apr 16 '26 02:04

Hari Reddy