-1

I am new to selenium. I want to validate the dynamic content of a web application. All the content is coming from database on the basis of some business logic. I have done with google search but got no success to find a solution.
Below is the HTML code which contains dynamic data in {{Curly}} brackets

<label class="form-check-label form-text" [for]="plan.planId">
        <input type="radio" class="input-radio" [id]="plan.planId" name="selectPlan" [value]="plan.planId" [(ngModel)]="selectPlanOption">
            {{plan.device}} - <span id="deviceLabel" class="text-uppercase"></span> <b><span id="animatedText" class="animate-text yellow-text weight-class">
                ${{plan.price}} ({{plan.discount}})</span></b>
</label>

Also, I have a doubt.

Is it good practice to validate dynamic content in Selenium?

Anyone help would be appreciated.

Thanks in advance.

Rahul Gupta
  • 504
  • 4
  • 17

1 Answers1

0

The desired element is a dynamic element so to extract the text from {{plan.device}} you need to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:

  • cssSelector:

    System.out.println((String)((JavaScriptExecutor)driver).executeScript("return arguments[0].childNodes[3].textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("label.form-check-label.form-text")))));
    
  • xpath:

    System.out.println((String)((JavaScriptExecutor)driver).executeScript("return arguments[0].childNodes[3].textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[@class='form-check-label form-text'][//input[@class='input-radio' and @name='selectPlan']]")))));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352