Find element with specific text in selenium

0 votes
How can I Find element with specific text in selenium?
Jan 9 in Selenium by Anjali
• 2,930 points
277 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 by Nabarupa

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,250 points
1,477 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,650 points
341 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

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,090 points
550 views
0 votes
1 answer
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,130 points
886 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
546 views
0 votes
1 answer
0 votes
1 answer

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

Hello @Jino, its amazing to explore ways ...READ MORE

answered Dec 21, 2018 in Selenium by Nabarupa
91 views