【发布时间】:2021-11-10 22:34:49
【问题描述】:
我已经使用 Angular 10 作为前端构建了一个简单的 Web 应用程序。现在我正在使用 pytest 和 Selenium Web 驱动程序编写测试脚本。我无法找到可靠的 XPATH 来检查我的网络应用程序的“星标”页面上是否存在文本。下面是应用程序外观的图片。
测试相对简单:导航到“星”页面并检查表中是否存在特定星(即 Sol)。而已。但是,我似乎找不到文本的有效 XPATH。我一直在开发者工具中尝试不同的 XPATH 查询,但它们都不起作用……任何东西。按钮、文字等
我还包含了相关页面的 HTML 代码:show-star.component.html
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary float-right m-2"
data-bs-toggle="modal" data-bs-target="#exampleModal"
(click)="addClick()"
data-backdrop="static" data-keyboard="false"
>
Add Star
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{{ModalTitle}}</h5>
<button type="button" class="btn-close"
data-bs-dismiss="modal" aria-label="Close"
(click)="closeClick()" >
</button>
</div>
<div class="modal-body">
<app-add-edit-star [star]="star" *ngIf="ActivateAddEditStarComp">
</app-add-edit-star>
</div>
</div>
</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Star ID</th>
<th>Star Name</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let dataItem of StarList">
<td>{{dataItem.StarID}}</td>
<td>{{dataItem.StarName}}</td>
<td>
<button type="button" class="btn btn-light mr-1"
data-bs-toggle="modal" data-bs-target="#exampleModal"
(click)="editClick(dataItem)"
data-backdrop="static" data-keyboard="false">
Edit
</button>
<button type="button" class="btn btn-light mr-1"
(click)="deleteClick(dataItem)">
Delete
</button>
</td>
</tr>
</tbody>
</table>
我认为它会像 //div[contains(text(),'Sol')] 这样简单,但似乎没有任何效果。 我到底做错了什么?
编辑 1: XPATH //td[contains(text(),'Sol')] 与开发工具中的任何选择器都不匹配
编辑 2:这是开发工具中的代码片段
【问题讨论】:
-
您能否将您的 pytest 代码或仅包含相关测试用例的代码包含在内?这将有助于确定那里是否缺少某些东西
-
您分享的HTML中没有包含Sol的td,请分享相关的HTML做进一步分析。
标签: javascript html selenium xpath pytest