The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Get Css attribute of any element

When you do automation testing, you have check which backgroud-color, font style, padding or margin is used for a element. and you can also check Css attribute of any element with the help of selenium script. Below it the code which help you to verify css attribute.


import java.util.List;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SearchWebElements
{
WebDriver driver = new FirefoxDriver();
private String baseUrl= "http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example";
@Test
public void findElementsColor(){
driver.get(baseUrl);
try{
    WebElement getCssValueElement = driver.findElements(By.id("by-id"));
String element_value = getCssValueElement.getCssValue("font-size");
Assert.assertequal(element_value,"Arial");
if(getCssValueElement.getCssValue("backgroud-color").contains("#ffffff"))
{
    System.Out.Print("Color Verify")'
}
else{
 System.Out.Print("Color Not Verify")'
}
    }
}
finally{
    //driver.close();
    driver.quit();
}
}
}
some time when browser convert #fffff  To rga(45.45.6.0), so Instead of #ffffff you can also used rga(45,45,6,0)

No comments

Post a Comment

Powered by Blogger.