I have a task where I need to retrieve the following text in black color highlighted in yellow. It is not within any tags and has no attribute. Once you locate a web element through the Inspect option, how do you retrieve that text? Also, what is it called when there is a text outside of a tag? enter image description here

  • Just noticed the xpath tag. Do you need it to be by XPath, as I often personally stay away from that selector unless I have no other choice. Dec 27 '19 at 15:42
  • Hi the test is in span tag , what have you tried so far? And what failed
    – PDHide
    Dec 27 '19 at 23:06
  • Please mention the tool and programming language
    – PDHide
    Dec 29 '19 at 11:15

This is just the innerText. If you were to use something like string innerText = _browser.FindElement(By.ClassName("test-id__field-label")).Text; the inner text (Duration) would be returned


There are several options to achieve it since you have mentioned XPath, I'll just write how you could get to that text or get that text

string duration = driver.FindElement(By.XPath("//span[@class='test-id__field-label']").Text;


WebElement duration = driver.FindElement(By.XPath("//span[@class='test-id__field-label']");
string duration_text = duration.Text;

To find the element with that text

WebElement duration = driver.FindElement(By.XPath("//span[text()='Duration']");

xpath: //span[@text() = 'Duration'] css : span[class = 'test-id__field-label'] if you are using selenium then class : driver.findelement(by.class("test-id__field-label"); if you are using Portractor class: element(by.className("test-id__field-label"));

Not the answer you're looking for? Browse other questions tagged or ask your own question.