feat: modify selectors with nth-child

This commit is contained in:
Rohit
2025-01-31 00:42:19 +05:30
parent 1ad4b5d97a
commit 4a7b111dcd

View File

@@ -263,6 +263,11 @@ export const BrowserWindow = () => {
} }
if (getList === true && !listSelector) { if (getList === true && !listSelector) {
let cleanedSelector = highlighterData.selector;
if (cleanedSelector.includes('nth-child')) {
cleanedSelector = cleanedSelector.replace(/:nth-child\(\d+\)/g, '');
}
setListSelector(highlighterData.selector); setListSelector(highlighterData.selector);
notify(`info`, t('browser_window.attribute_modal.notifications.list_select_success')); notify(`info`, t('browser_window.attribute_modal.notifications.list_select_success'));
setCurrentListId(Date.now()); setCurrentListId(Date.now());
@@ -275,13 +280,25 @@ export const BrowserWindow = () => {
// Add fields to the list // Add fields to the list
if (options.length === 1) { if (options.length === 1) {
const attribute = options[0].value; const attribute = options[0].value;
let currentSelector = highlighterData.selector;
if (currentSelector.includes('>')) {
const [firstPart, ...restParts] = currentSelector.split('>').map(p => p.trim());
const listSelectorRightPart = listSelector.split('>').pop()?.trim().replace(/:nth-child\(\d+\)/g, '');
if (firstPart.includes('nth-child') &&
firstPart.replace(/:nth-child\(\d+\)/g, '') === listSelectorRightPart) {
currentSelector = `${firstPart.replace(/:nth-child\(\d+\)/g, '')} > ${restParts.join(' > ')}`;
}
}
const newField: TextStep = { const newField: TextStep = {
id: Date.now(), id: Date.now(),
type: 'text', type: 'text',
label: `Label ${Object.keys(fields).length + 1}`, label: `Label ${Object.keys(fields).length + 1}`,
data: data, data: data,
selectorObj: { selectorObj: {
selector: highlighterData.selector, selector: currentSelector,
tag: highlighterData.elementInfo?.tagName, tag: highlighterData.elementInfo?.tagName,
shadow: highlighterData.elementInfo?.isShadowRoot, shadow: highlighterData.elementInfo?.isShadowRoot,
attribute attribute