Selenium: Unable to Scrape Text Via XPath Selenium: Unable to Scrape Text Via XPath selenium selenium

Selenium: Unable to Scrape Text Via XPath


This XPath

//span[@data-field='fasttrackcountdown']

will select this element

<span data-field="fasttrackcountdown">10 hours and 51 minutes</span>

in your HTML, as requested.


As you are saying your xPath is correct then It might be timing, at the time when you're going to find element, may be it wouldn't present with text, you should try using WebDriverWait to wait until element visible with cssSelector as span[data-field='fasttrackcountdown'] as below(Assuming you are using Java) :-

WebDriverWait wait = new WebDriverWait(driver, 10);WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span[data-field='fasttrackcountdown']")));el.getText();

If still you are not able to find text, you should use getAttribute("innerHTML") as below :-

el.getAttribute("innerHTML");

Or try using getAttribute("textContent") as below :-

el.getAttribute("textContent");

Hope it helps...:)