Get color attribute value

36 views
Skip to first unread message

pavankumar abvg

unread,
Dec 2, 2016, 7:19:28 PM12/2/16
to Selenium Users
Hi Team,

I am trying to get color attribute value of 'Sign up' link in 'goibibo.com' But it is returning the null value.

Below is the code:

WebElement objSignUp = driver.findElement(By.linkText("Sign up"));
JavascriptExecutor jsDriver = ((JavascriptExecutor)driver);
String s = (String) jsDriver.executeScript("return arguments[0].getAttribute('color');", objSignUp);
System.out.println("Element default color : " + s);

Thanks,
Pavan

Andreas Tolfsen

unread,
Dec 3, 2016, 4:20:21 AM12/3/16
to seleniu...@googlegroups.com
Attributes are not properties. Learn the difference.

What you want is:

String s = (String) jsDriver.executeScript(
"return arguments[0]['color']", objSignUp);

Or:

String s = objSignup.getAttribute();

Current Selenium versions conflate attributes and properties when
calling getAttribute. This is bound to change in future versions.

Ahmet Ozkesek

unread,
Dec 4, 2016, 8:46:16 PM12/4/16
to Selenium Users
Hi Pavan,

if we look at the element code 

<a href="javascript:void(0)" onclick="try{ gi.utils.register(); } catch (e) { window.location.href = '/accounts/register/?next=' + location.href; } ">Sign up</a>

there is no color attribute but css/style.  So you should try to get css value of color.  

By the way why do you run javascript while you have already web-element itself? 
Have you tried this before
objSignUp.getCssValue("color")

AO,
Thanks,

3 Aralık 2016 Cumartesi 03:19:28 UTC+3 tarihinde pavankumar abvg yazdı:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages