Selenium IDE 无法根据其标题属性捕获元素

Selenium IDE is failing to capture element based off its title attribute

我在 Mac Big Sur 上为 Chrome 使用硒 IDE。我注意到特定页面的 ID 不断变化,因此我希望我的 SElenium 播放使用更稳定的东西。具体来说,我想捕获对此元素的点击 ...

<th scope="col" role="columnheader" data-field="parentName" aria-haspopup="true" rowspan="1" data-title="Parent Institution" data-index="1" id="05abd234-04a8-409c-99e9-90fd772f0dd2" class="k-header k-with-icon k-filterable" data-role="columnsorter"><a class="k-grid-filter" href="#" title="Filter" aria-label="Filter" tabindex="-1"><span class="k-icon k-i-filter"></span></a><a class="k-link" href="#">Parent Institution</a></th>

所以我想我可以使用 TH title 属性。在我的“.side”文件中,我设置了 select 或者像这样

}, {
  "id": "b3839cf6-9347-4a43-9208-922e2975fc33",
  "comment": "click parent menu",
  "command": "click",
  "target": "css=title^='Parent Institution'",
  "targets": [
    ["css=#5ba47ffd-b9ec-41e6-b4e6-924bf3d688bc", "css:finder"],
    ["xpath=//th[@id='dd03982f-9fdb-4140-bb24-93f9582c6bad']/a/span", "xpath:idRelative"],
    ["xpath=//th[3]/a/span", "xpath:position"]
  ],
  "value": ""
}, {

但是在播放的时候,IDE好像还是检测不到这个元素。我应该根据 TH“title”属性以其他方式准确地 select CSS 编写此命令吗?

<th>元素的id属性值是动态生成的。因此,每次您访问应用程序或在某个时间间隔内,<th> 元素的 id 属性的值将获取改变了。

此外,可点击的元素是标签:

<a class="k-link" href="#">Parent Institution</a>

解决方案

要单击该元素,您可以使用以下任一方法

  • 使用link_text:

    Parent Institution
    
  • 使用css_selector:

    th[data-field='parentName'][data-title='Parent Institution'] a.k-grid-filter[title='Filter'][aria-label='Filter'] +a.k-link
    
  • 使用 xpath:

    //th[@data-field='parentName'][@data-title='Parent Institution']//a[text()='Parent Institution']