Find element with specific text in selenium

0 votes
How can I Find element with specific text in selenium?
Jan 9, 2019 in Selenium by Anjali
• 2,950 points
4,962 views

1 answer to this question.

0 votes

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.

answered Jan 9, 2019 by Nabarupa
thank you so much
Hey do upvote the answer in case you found it helpful!

Related Questions In Selenium

0 votes
1 answer

Searching for the element with   symbol in selenium

Use Below: //div[@class='Tips' and text()='\u00a0'] READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,360 points
5,744 views
0 votes
1 answer

Source code to find element in Selenium-java

You are probably looking at the WebDriver interface alone. But, ...READ MORE

answered Apr 24, 2018 in Selenium by king_kenny
• 3,710 points
868 views
+1 vote
2 answers
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,475 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,487 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,567 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,803 views
0 votes
1 answer
0 votes
2 answers

How to use link as a locator to find element in selenium?

driver.findElement(By.linkText("link")).click(); READ MORE

answered Sep 3 in Selenium by Sri
• 2,970 points
276 views