2022-11-21 01:08:12 +00:00
|
|
|
export const getFormElementIdByLabel = async (
|
|
|
|
text: string,
|
|
|
|
className: string
|
|
|
|
) => {
|
2023-01-05 11:21:22 +00:00
|
|
|
// Remove leading dot if className is passed with it.
|
|
|
|
className = className.replace( /^\./, '' );
|
|
|
|
|
2023-01-09 16:44:53 +00:00
|
|
|
const labelElement = await page.waitForXPath(
|
2022-11-21 01:08:12 +00:00
|
|
|
`//label[contains(text(), "${ text }") and contains(@class, "${ className }")]`,
|
|
|
|
{ visible: true }
|
|
|
|
);
|
2023-01-09 16:44:53 +00:00
|
|
|
return await page.evaluate(
|
2022-11-21 01:08:12 +00:00
|
|
|
( label ) => `#${ label.getAttribute( 'for' ) }`,
|
|
|
|
labelElement
|
|
|
|
);
|
|
|
|
};
|