简体   繁体   中英

Unable to locate element using ID, XPath and CSS Selector

I am using atata framework with C#. I am trying to locate web element to select all rows but neither Id, CSS Path or XPath are able to find.

I have used ID, XPath and CSS Selector

[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

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

  1. For the first <div> 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;">

    As it is a div , not a button element then use general puprose Control type:

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

     <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. Try the below code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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