How to use xpath to get a specific text from a website?

+1 vote
Hello, I am new to selenium and am learning about Xpath, how can I use Xpath to locate a text in any website?
Dec 19, 2018 in Selenium by Jino
• 5,770 points
436 views

1 answer to this question.

0 votes

The task is to get the text using XPATH. XPath is a locator used to locate an element using the XML path. XPath stores the key-value pair similar to HTML tags.

So, inorder to find the Text all you need to do is:

driver.findElement(By.xpath("//*[contains(text(),'the text you are searching for')]"));

This way you can find the text you are looking for.

Hope this helps @Jino

answered Dec 19, 2018 by Nabarupa

Related Questions In Selenium

0 votes
2 answers

How to get the text from a website using selenium?

driver.findElement(By.cssSelector("p")).getText() or  IWebElement element = Browser.GetElementByCssSelector("div.loginbox p"); string text = ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
11,239 views
+1 vote
2 answers

How to get typed text from a textbox by using Selenium Webdriver?

Hey Ashmita, to get the typed text ...READ MORE

answered Jun 24, 2019 in Selenium by Abha
• 27,930 points
12,729 views
0 votes
0 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,520 points
3,802 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,785 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,758 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
3,120 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 13,180 points
7,343 views
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
301 views