【问题标题】:XPATH Query for Angular 10 ApplicationAngular 10 应用程序的 XPATH 查询
【发布时间】: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


【解决方案1】:

你确定它被包裹在一个 div 中吗?

"//td[contains(text(),'Sol')]"

【讨论】:

  • 这也不起作用。我将您的建议粘贴到开发工具中,但没有匹配的选择器。
  • 您是否使用开发工具 xpath 语法 $x("pathhere")?应该是这样的: $x("//td[contains(text(),'Sol')]")
  • 这也不起作用
  • 这似乎适用于 Firefox 开发工具,但不适用于 MS Edge。谁能解释一下为什么?
猜你喜欢
  • 2016-08-25
  • 2017-05-23
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 2021-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多