Hi all i am trying to get border color of an extjs 4.2 form control text field using getCssValue method. But i am not able to fetch it. it is returning me blank. Below is my code snippet u can try this as is.
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestClass
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
Thread.sleep(2000);
driver.get("http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/dynamic.html");
Thread.sleep(2000);
WebElement element=driver.findElement(By.xpath(".//input[@name='first']"));
Thread.sleep(2000);
element.sendKeys("");
element.sendKeys(Keys.TAB);
Thread.sleep(2000);
System.out.println("'"+element.getCssValue("border-color")+"'");
}
}
Webdriver version 2.33 (Java binding)
FF 22
How to get border color or other css values look in Computed there are all values that you can get:
getCssValue("border-bottom-color")
returns rgba(209, 219, 223, 1) and need to clear it (this will work for rgba and rgb):
String rgb[] = driver.findElement(By.name("login[email]")).getCssValue("border-bottom-color").replaceAll("(rgba)|(rgb)|(\\()|(\\s)|(\\))","").split(",");
Now our rgb is in array using this method to parse it
String hex = String.format("#%s%s%s", toBrowserHexValue(Integer.parseInt(rgb[0])), toBrowserHexValue(Integer.parseInt(rgb[1])), toBrowserHexValue(Integer.parseInt(rgb[2])));
private static String toBrowserHexValue(int number) {
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
while (builder.length() < 2) {
builder.append("0");
}
return builder.toString().toUpperCase();
}
From this rgba(209, 219, 223, 1) we got this #D1DBDF
P.S. Source of parsing int rgb to hex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With