fix: check type of className

This commit is contained in:
karishmas6
2024-09-03 06:13:26 +05:30
parent e727d11861
commit f09cb3fc73

View File

@@ -786,14 +786,16 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
};
export const getChildSelectors = async (page: Page, parentSelector: string, maxDepth: number = 2): Promise<string[]> => {
export const getChildSelectors = async (page: Page, parentSelector: string, maxDepth: number = 5): Promise<string[]> => {
try {
const childSelectors = await page.evaluate(({ parentSelector, maxDepth }: { parentSelector: string, maxDepth: number }) => {
function getNonUniqueSelector(element: HTMLElement): string {
let selector = element.tagName.toLowerCase();
if (element.className) {
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
// Ensure that className is a string before splitting
const className = typeof element.className === 'string' ? element.className : '';
if (className) {
const classes = className.split(/\s+/).filter((cls: string) => Boolean(cls));
if (classes.length > 0) {
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
if (validClasses.length > 0) {