Bastian
Bastian

Reputation: 1237

How to make selenium wait until text in specific place

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

Upvotes: 1

Views: 1385

Answers (3)

CEH
CEH

Reputation: 5909

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);

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193108

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"));

Upvotes: 4

arcadeblast77
arcadeblast77

Reputation: 570

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?

Upvotes: -1

Related Questions