-2

How can I get this element's text:

<span jsan="7.widget-pane-link,0.role" style="">Hi</span>

In other words, how can I get the text Hi by Using attribute GetAttribute("jsan")?

Guy
  • 46,488
  • 10
  • 44
  • 88
Ahmed Mohamed
  • 29
  • 1
  • 6

1 Answers1

1

To retrieve the text Hi from the element you have to induce WebDriverWait for ElementIsVisible() and you can use either of the following Locator Strategies as solutions:

  • Using CssSelector and Text property:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.CssSelector("span[jsan*='widget-pane-link'][jsan$='role']"))).Text);
    
  • Using XPath and GetAttribute() method:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//span[contains(@jsan, 'widget-pane-link') and contains(@jsan, 'role')]"))).GetAttribute("innerHTML"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352