-1

I would like to get value from text between ::before ::after in selenium. I suppose it's impossible to do it by xpath, what JSexecutor code I can use?

Value I would like to get:

Value i would like to get

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
knalepa
  • 29
  • 3

1 Answers1

-1

::before and ::after are the css and are not printable text. So to print the text Widget you can use either of the following Locator Strategies:

  • Using cssSelector:

    System.out.println(wd.findElement(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading")).getText());
    
  • Using xpath:

    System.out.println(wd.findElement(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']")).getText());
    

Ideally, to extract the text Some Text as the element is a dynamic element, you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:

  • Using cssSelector:

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.linkbox.margin-bottom-20 > h1.heading"))).getText());
    
  • Using xpath:

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='linkbox margin-bottom-20']/h1[@class='heading']"))).getText());
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352