0

In my Selenium webdriver, I search for text based on a certain keyword:

new WebDriverWait(driver, 
TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists((By.PartialLinkText(stringKeywords))));

I would like to grab the full text I have found and save it into a string. How would I be able to do this? I found this somewhere, but it wont let me use it as a string because it is a IWebElement. Could it help me anyway?

IWebElement txtbox = driver.FindElement(By.PartialLinkText(stringKeywords));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
HellFireElite
  • 39
  • 1
  • 7

2 Answers2

1

Once you are able to locate the webelement using PartialLinkText, to extract the complete innerText you can use the GetAttribute() method as follows:

Console.WriteLine(driver.FindElement(By.PartialLinkText(stringKeywords)).GetAttribute("innerHTML"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
string txt = driver.FindElement(By.PartialLinkText(stringKeywords)).Text;