我有一个表格,下面是我正在编写selenium测试的html行的描述:
<mat-row _ngcontent-kgo-c23="" class="mat-row ng-star-inserted" role="row">
<!---->
<mat-cell _ngcontent-kgo-c23="" class="mat-cell cdk-column-id mat-column-id ng-star-inserted" role="gridcell">
<a _ngcontent-kgo-c23="" ng-reflect-router-link="/dir,208" href="/claim/208">208</a>
</mat-cell>
<mat-cell _ngcontent-kgo-c23="" class="mat-cell cdk-column-firstName mat-column-firstName ng-star-inserted" role="gridcell">
George
</mat-cell>
</mat-row>
以下是测试:
List<WebElement> idRows = super.wait(WAIT, INTERVAL).until(driver -> driver.findElements(By.className("mat-column-id")));
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Validate only one row exist in the search result
assertEquals(1,idRows.size());
//The result has is "208" and name "George"
WebElement firstNameInSearchResult = webDriver.findElement(By.className("cdk-column-firstName"));
System.out.println("===========>" + firstNameInSearchResult.gettext()+", " + idRows.get(0));
assertTrue(firstNameInSearchResult.getText().contains("George"));
assertTrue(idRows.get(0).getText().contains(searchId));
system.out.println显示空文本。print语句之后的Assert失败。我用正确的方法进行文本验证了吗?
1条答案
按热度按时间ddhy6vgd1#
这些元素是角元素。所以要提取208和乔治的文本,你必须归纳出
visibilityOfElementLocated()
您可以使用以下任一定位器策略:打印文本:
使用xpath和
getAttribute("innerHTML")
:打印文本:
使用xpath和
getText()
: