-
-
Notifications
You must be signed in to change notification settings - Fork 750
Closed
Description
What are you trying to achieve?
https://codecept.io/locators/#custom-strategy-locators
This Custom Strategy Locators feature is currently only available on WebdriverIO. However, since it's just a JavaScript execution to return element(s), it should be technically possible to export to Playwright (and the other web automation helpers). If we can do so, it makes easier to find elements more flexibly.
Example: Look up a table cell by the header row and column
// in codecept.conf.js
const findTableCellByHeader = (selector, rowHeader, colHeader) => {
// Find the table
const table = root.querySelector(selector)
if (!table) {
throw new Error(`Table not found: ${selector}`);
}
// Find the row
const row = Array.from(table.querySelectorAll('tr')).find(
(tr) => tr.querySelector('th')?.textContent === rowHeader
);
if (!row) {
throw new Error(`Row not found: ${rowHeader}`);
}
// Find the column index
const colIndex = Array.from(table.querySelectorAll('tr')[0].cells).findIndex(
(cell) => cell.textContent === colHeader
);
if (colIndex === -1) {
console.log('Column not found');
return null;
}
// Return the cell at the intersection of the row and column
return row.cells[colIndex];
}
// under WebDriver Helpers Configuration
WebDriver: {
...
customLocatorStrategies: {
findTableCellByHeader
}
}
This is the example of Webdriver helper, and I would like to enable it to the Playwright helper.
What do you get instead?
Currently the CustomLocator plugin only allows to use CSS or XPath, does not allow to find elements by JavaScript.
Details
N/A
Copilot
Metadata
Metadata
Assignees
Labels
No labels