Reputation: 61
I am trying to click on a link. I have verified the xpath for that element using SelectorsHub and Chropath as well, so there is no issue with the locator. I have tried 3-4 xpaths but I keep on getting the same error. Please see below the error which I am getting in console:-
locator.click: Target closed =========================== logs =========================== waiting for selector "//span[contains(text(),'Received Date')]/following-sibling::span/span/span[@aria-label='caret-up']" selector resolved to visible <span role="img" aria-label="caret-up" class="anticon …>… attempting click action waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling checking that element receives pointer events at (485.95,278.14) … intercepts pointer events retrying click action, attempt #1 waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling checking that element receives pointer events at (485.95,278.14) … intercepts pointer events
Please see below the HTML for this:-
<div class="ant-table-filter-column"><span class="ant-table-column-title"><div class="ant-table-column-sorters"><span class="ant-table-column-title">Received Date</span><span class="ant-table-column-sorter ant-table-column-sorter-full"><span class="ant-table-column-sorter-inner"><span role="img" aria-label="caret-up" class="anticon anticon-caret-up ant-table-column-sorter-up active"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="caret-up" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M858.9 689L530.5 308.2c-9.4-10.9-27.5-10.9-37 0L165.1 689c-12.2 14.2-1.2 35 18.5 35h656.8c19.7 0 30.7-20.8 18.5-35z"></path></svg></span><span role="img" aria-label="caret-down" class="anticon anticon-caret-down ant-table-column-sorter-down"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="caret-down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"></path></svg></span></span></span></div></span><span role="button" tabindex="-1" class="ant-dropdown-trigger ant-table-filter-trigger"><span role="img" aria-label="search" class="anticon anticon-search"><svg viewBox="64 64 896 896" focusable="false" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0011.6 0l43.6-43.5a8.2 8.2 0 000-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"></path></svg></span></span></div>
Below are the xpaths which I have tried:-
Code for clicking - await this.page.locator("//span[contains(text(),'Received Date')]/following-sibling::span/span/span[@aria-label='caret-up']").click();
Upvotes: 0
Views: 4127
Reputation: 1782
Please, try to avoid very long or complex Xpaths. They make your code unreadable, they can make errors and they are not the right way to find elements and click on them.
Tell me if this works for you:
button = self.page.locator('//span[contains(text() \
,'Received Date')]').first
button.click()
Upvotes: 0