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
7,981 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

How do I find an element that contains specific text in Selenium WebDriver (Python)?

Try the following: driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]") I hope this ...READ MORE

answered Nov 27, 2020 in Selenium by Gitika
• 65,910 points
5,718 views
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
8,670 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
1,716 views
+1 vote
2 answers
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,500 points
12,616 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 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,910 points
6,629 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 3, 2020 in Selenium by Sri
• 3,190 points
7,517 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 4, 2020 in Selenium by Sri
• 3,190 points
1,209 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP