简体   繁体   English

无法使用 ID、XPath 和 CSS 选择器定位元素

[英]Unable to locate element using ID, XPath and CSS Selector

I am using atata framework with C#.我在 C# 中使用 atata 框架。 I am trying to locate web element to select all rows but neither Id, CSS Path or XPath are able to find.我正在尝试定位 web 元素以选择所有行,但 Id、CSS Path 或 XPath 都无法找到。

I have used ID, XPath and CSS Selector我使用过 ID、XPath 和 CSS 选择器

[FindById("com.kronos.wfc.ngui.genies.selectall")]
public Button<_> SelectAllRows { get; private set; }

[FindByXPath("div[@id=com.kronos.wfc.ngui.genies.selectall]")]
public Button<_> SelectAllRows { get; private set; }

My page object should be located.我的页面对象应该被定位。 Details of paths are:路径详情如下:

Element:元素:

<div class="widget-button btn-group margin-mini shrinkable" title="Select All Rows" 
id="com.kronos.wfc.ngui.genies.selectall" style="display: inline-block;">

<div class="top-bar"><span></span></div>

<button type="button" class="btn btn-rounded widget-button-icon" id="com.kronos.wfc.ngui.genies.selectall_btn">
<i class="icon-k-select-all"></i></button><div class="icon-label"><span>Select All Rows</span></div></div>

Selector: #com.kronos.wfc.ngui.genies.selectall选择器:#com.kronos.wfc.ngui.genies.selectall

XPath: //*[@id="com.kronos.wfc.ngui.genies.selectall"] XPath: //*[@id="com.kronos.wfc.ngui.genies.selectall"]

  1. For the first <div> element:对于第一个<div>元素:

     <div class="widget-button btn-group margin-mini shrinkable" title="Select All Rows" id="com.kronos.wfc.ngui.genies.selectall" style="display: inline-block;">

    As it is a div , not a button element then use general puprose Control type:因为它是一个div ,而不是一个button元素,所以使用一般的 puprose Control类型:

     [FindById("com.kronos.wfc.ngui.genies.selectall")] public Control<_> SelectAllRows { get; private set; }
  2. For the second <button> element:对于第二个<button>元素:

     <button type="button" class="btn btn-rounded widget-button-icon" id="com.kronos.wfc.ngui.genies.selectall_btn">

    The following should find the element if it's actually visible:如果它实际上是可见的,则以下内容应该找到该元素:

     [FindById("com.kronos.wfc.ngui.genies.selectall_btn")] public Button<_> SelectAllRows { get; private set; }

    If the element is not visible:如果元素不可见:

     [FindById("com.kronos.wfc.ngui.genies.selectall_btn", Visibility = Visibility.Any)] public Button<_> SelectAllRows { get; private set; }

Anyway, figure out which element is actually visible and should be interacted with.无论如何,弄清楚哪个元素实际上是可见的并且应该与之交互。

I think you should perform the click action on the button element instead of the div element.我认为您应该在button元素而不是div元素上执行单击操作。 Try the below code:试试下面的代码:

[FindById("com.kronos.wfc.ngui.genies.selectall_btn")]
public Button<_> SelectAllRows { get; private set; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM