Home > Enterprise >  How to wait till some value to be present on HTML tag?
How to wait till some value to be present on HTML tag?

Time:09-29

I can use Thread.sleep(); but my boss doesn't want me to do that so I used explicit wait

webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xPath("")));

but it is not working as well because the xpath is not present as the data(Text) that appears in sometime.

CodePudding user response:

For that kind of situation apply Explicit wait such that the attribute of the tag is updated with some value.

wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("xpath/tag[contains(@Unit,'Abc')]")));

You can also refer This Link

CodePudding user response:

  • If you know what text will be presented then you can use textToBePresentInElementLocated method. Let's see below example,

HTML#1:

  <input class="google"> Text </input>

Wait till text presents if you know the expected text

wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//input[@class='google']"), "Text"));
  • If that value (abc) resides in an attribute then you can use below approach.

HTML#2:

  <input class="google" value="Text" >

Wait till attribute have some value

WebElement element = driver.findElement(By.xpath("//input[@class='google']"));
wait.until(ExpectedConditions.attributeToBeNotEmpty(element, "value"));

How to read properties file?

https://stackoverflow.com/a/69236087/7731623

Dynamic xPath:

/** Code to read properties file **/

String inputData = readProperties.getProperty("Data").trim();
driver.findElement(By.xpath("//input[@class='" inputData "']"));
        wait.until(ExpectedConditions.attributeToBeNotEmpty(element, "value"));
  • Related