1

I have a question regarding selenium wait. I want selenium to wait until a text displayed in specific xpath. the text is: "Hensley and Workman Trading" the xpath is: //td[@class='td_company ng-star-inserted'] I tried the wait until.attributeTobe function but can not make it wait. What I am doing wrong (I think the until row is not working, the order or condition true)

public static void getWebElementByXpathWithWaitTextToBeSeen()
    {
        WebDriver driver2 = WebDriverMgr.getDriver();
      //  driver2.manage().timeouts().implicitlyWait(IMPLICIT_WAITE, TimeUnit.SECONDS);
        WebDriverWait wait = new WebDriverWait(driver2,EXPLICIT_WAITE);
        wait.until(ExpectedConditions.attributeToBe(By.xpath("//td[@class='td_company ng-star-inserted']"),"Hensley and Workman Trading","true"));
    }

From Dev Tool: enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bastian
  • 1,089
  • 7
  • 25
  • 74

3 Answers3

4

To wait for the text Hensley and Workman Trading to be displayed within the WebElement you can use the following Locator Strategies:

new WebDriverWait(driver, 20).until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//td[@class='td_company ng-star-inserted']"), "Hensley and Workman Trading"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

OpenQA.Selenium.Support.UI implements wait.Until(expectedCondition) functionality. Here's an example of what you're trying to do:

  public static void WaitForElementText(this IWebDriver driver, By by, string text)
  {
      var wait = new WebDriverWait(driver, TimeoutScope.Current.Timeout);
      wait.Until(d => d.FindElement(by).Text == text);
  }

In your case, it would look like this:

      var wait = new WebDriverWait(driver, TimeoutScope.Current.Timeout);
      wait.Until(d => d.FindElement(By.XPath("//td[@class='td_company ng-star-inserted']")).Text == text);
CEH
  • 5,701
  • 2
  • 16
  • 40
-1

Try

" Hensley and Workman Trading " // With the extra spaces

instead of

"Hensley and Workman Trading"

Not positive, but those spaces may be throwing it off?

arcadeblast77
  • 560
  • 2
  • 12
  • wait.until(ExpectedConditions.attributeToBe(By.xpath("//td[@class='td_company ng-star-inserted']"),"Hensley and Workman Trading","true")); - Is this the correct syntax with "true"?\ – Bastian Sep 19 '19 at 13:19
  • I have not used Java with Selenium in years but that `"true"` does not seem correct when I'm reading the docs. I actually would recommend also checking out `attributeContains` instead of `attributeToBe`. Less brittle. – arcadeblast77 Sep 19 '19 at 13:25
  • Docs say: **locator** - used to define WebElement to check its parameters **attribute** - used to define css or html attribute **value** - used as expected attribute value – arcadeblast77 Sep 19 '19 at 13:28
  • There is also `textMatches` in the `ExpectedConditions` doc, which could be a really clean solution. – arcadeblast77 Sep 19 '19 at 13:30