Skip to content

Instantly share code, notes, and snippets.

@ssmiech
Created June 18, 2013 10:06
Show Gist options
  • Save ssmiech/5804176 to your computer and use it in GitHub Desktop.
Save ssmiech/5804176 to your computer and use it in GitHub Desktop.
Element's font weight and color
package selenium;
import java.sql.Driver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import selenium.Table;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.firefox.FirefoxDriver;;
public class test {
private static WebDriver driver;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.get("http://www.linkedin.com/groupAnswers?viewQuestionAndAnswers=&discussionID=250739191&gid=961927&commentID=144999230&trk=view_disc&fromEmail=&ut=0Y244D3ga9PlM1");
System.out.println(getFontWeight());
System.out.println(getFontColor());
}
public static String getFontWeight() {
String script = "var element = document.querySelector('#section-header h1 span'); return window.getComputedStyle(element).getPropertyValue(\"font-weight\")" ;
return (String) ((JavascriptExecutor) driver).executeScript(script);
}
public static String getFontColor() {
String script = "var element = document.querySelector('#section-header h1 span'); return window.getComputedStyle(element).getPropertyValue(\"color\")" ;
return (String) ((JavascriptExecutor) driver).executeScript(script);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment