Getting Text of an element using contains in xpath

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class “Class Name”
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty(“webdriver.chrome.driver”,”path”);
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.MILLISECONDS);
driver.get(“https://login.salesforce.com/”);
driver.findElement(By.cssSelector(“input[class=’input r4 wide mb16 mt8 username’]”)).sendKeys(“aaa”);
driver.findElement(By.cssSelector(“input[class=’input r4 wide mb16 mt8 password’]”)).sendKeys(“test”);
driver.findElement(By.cssSelector(“input[value=’Log In’]”)).click(); Thread.sleep(5000); String ele=driver.findElement(By.xpath(“//div[contains(text(),’Please check your username and password.’)]”)).getText();
System.out.println(ele); driver.close();
}
}

Leave a comment