Search code examples
c#angularseleniumautomated-testsatata

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"]


Solution

    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.