You can use Xpath as the locator and then search for the text you want in the webpage.
Here is a sample example :-
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonShoping {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.in");
driver.findElement(By.xpath("//*[text()='Hello. Sign in']")).click();
Thread.sleep(3000);
driver.findElement(By.id("ap_email")).sendKeys("Username@gmail.com",Keys.ENTER);
Thread.sleep(2000);
driver.findElement(By.id("ap_password")).sendKeys("Password",Keys.ENTER);
Thread.sleep(4000);
driver.close();
}
}
Hope this helps you.