I am using the below code with the expectation that it would locate the visible button
element = @browser.button(text: 'Search', visible: true)
And it's not locating the visible button. But the below code locating the visible button
element = @browser.element(xpath: "//button[text()='Search']", visible: true)
Is this expected? Or is it an issue?
HTML Code
<button type="button" title="" data-uid="DSDL_U1" data-action="search" data-viewitemid="DSDL_U1_-1_L21" triggeredactionhandler="search" buttonprocesstarget="CUSTOMER_IND_QUICK_SEARCH_BY_ID_NAME" class="icon icon-detail-search" id="DSDL_U1_-1_L21_L_1_C" tabindex="10047">Search</button>
@justin
To answer your question
@browser.buttons(text: 'Search').count
return 6
@browser.buttons(text: 'Search', visible: true).count
return 2
Now I checked
@browser.buttons(text: 'Search', visible: true)[0].present?
returns true
but If I click, then it returns
element click intercepted: Element <button tabindex="5" type="button" class="icon icon-detail-url" id="U1_-1_L5_L_1_C" style="outline: orangered solid 2px !important; background-color: rgb(255, 255, 255);">...</button> is not clickable at point (43, 258). Other element would receive the click: <div id="homePageSearch" class="searchGrpContainer homePageSearch populated" data-renderer="menu" data-headertype="button" data-style="tree" data-zone="overlay">...</div>
(Session info: chrome=89.0.4389.90)
But If write
@browser.buttons(text: 'Search',visible: true)[1].present?
this returns true but If triggers the click, then it clicks.
You asked me the html of the two elements
@browser.buttons(text: 'Search',visible: true)[0].html
returns
<button tabindex="5" type="button" class="icon icon-detail-url" id="U1_-1_L5_L_1_C" style="outline: orangered solid 2px !important; background-color: rgb(255, 255, 255);"><span>Search</span></button>
Second element
@browser.buttons(text: 'Search',visible: true)[1].html
returns
<button type="button" title="" data-uid="DSDL_U1" data-action="search" data-viewitemid="DSDL_U1_-1_L21" triggeredactionhandler="search" buttonprocesstarget="CUSTOMER_IND_QSEARCH_PARTYID_ALTCUSTID" class="icon icon-detail-search" id="DSDL_U1_-1_L21_L_5_C" tabindex="10047">Search</button>
When I click the first search button, it opens another window inside the same html, In that new window another search button is there, So it's matching the first search button(which I clicked to open) and the second search button is in the new window which I about to click. But program detects two search buttons as visible.