Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何验证SeleniumJava中数据库驱动的web应用程序的动态内容_Java_Selenium_Selenium Webdriver - Fatal编程技术网

如何验证SeleniumJava中数据库驱动的web应用程序的动态内容

如何验证SeleniumJava中数据库驱动的web应用程序的动态内容,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我是硒的新手。 我想验证web应用程序的动态内容。所有内容都是基于某些业务逻辑从数据库中获取的。我已经完成了谷歌搜索,但没有找到解决方案。 下面是HTML代码,它包含{{Curly}}括号中的动态数据 <label class="form-check-label form-text" [for]="plan.planId"> <input type="radio" class="input-radio" [id]="plan.planId" name="sele

我是硒的新手。 我想验证web应用程序的动态内容。所有内容都是基于某些业务逻辑从数据库中获取的。我已经完成了谷歌搜索,但没有找到解决方案。
下面是HTML代码,它包含
{{Curly}}
括号中的动态数据

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

{{plan.device}}-
${{plan.price}}({{plan.discount}})
还有,我有一个疑问

验证硒的动态含量是否是一种良好的做法

任何人都将不胜感激


提前感谢。

所需的元素是一个动态元素,因此要从
{plan.device}
中提取文本,您需要为
元素的可见性引入WebDriverWait()
,并且您可以使用以下任一选项:

  • css选择器

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

您试图提取
计划.设备
计划.价格
计划.折扣
?我可以访问
计划.设备
计划.价格
计划.折扣
。但这些字段具有动态内容,可以是任何内容。因此,我的问题是如何验证这些字段。查看已发布的答案,一旦您能够提取所需的文本,断言文本将不再是任务。