Trying to find the ancestor element using Selenide library on a website. The ancestor element is <div class="BorderGrid-cell" ...>.
The .closest(".BorderGrid-cell") method works well. However, the .closest("div.BorderGrid-cell") method does not work (error "NoSuchElementException: no such element: Unable to locate element"). Why is this?
Coding to inspect the page https://github.com/selenide/selenide. The code should identify the list of contributors and hover over the first contributor in the list. Since there are no suitable locators in the list, I search for the text "Contributors," then move up to the ancestor of the located tag (via closest), and proceed down to the list.
Working code:
$("div.Layout-sidebar").$(byText("Contributors")).closest(".BorderGrid-cell").$$("ul li").first().hover();
Non-working code:
$("div.Layout-sidebar").$(byText("Contributors")).closest("div.BorderGrid-cell").$$("ul li").first().hover();
The only difference is the 'div' in the .closest() method. It was expected that both codes would function similarly. Why does the second one fail to work?
Code on Github: https://github.com/Anton248/QA_guru_getting_started_Java/blob/master/src/test/java/github/DifferenceBetweenTwoExpressions.java