Reading an element contnet without using XPath by WebDriver

Some times we can access an element with class only but the class contans compound values but className will not accept compound values.

In order to handle these situatuions we need to write differently. Following code will help you to handle it.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Webelements {
 static WebDriver driver;
 // Browser startup
 @BeforeClass
 public void setup() {
 
  driver = new FirefoxDriver();
 }
 // Functionality of Test Case
 @Test
 public void testGoogle() throws InterruptedException, IOException {
 
  driver.get("http://quirksmode.org/css/selectors/multipleclasses.html");
//  System.out.println(driver.findElement(By.className("underline small")).getText());
  System.out.println(driver.findElement(By.cssSelector("p[class='underline small']")).getText());
 
  Thread.sleep(3000);
 }
 @AfterClass
 public void tear() {
  driver.close();
 }