Skip to content

Commit feb30b9

Browse files
committed
feat: add nth-child selectors for td tag
1 parent 4ac55f0 commit feb30b9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server/src/workflow-management/selector.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,13 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
869869
function getNonUniqueSelector(element: HTMLElement): string {
870870
let selector = element.tagName.toLowerCase();
871871

872+
if (selector === 'td' && element.parentElement) {
873+
// Find position among td siblings
874+
const siblings = Array.from(element.parentElement.children);
875+
const position = siblings.indexOf(element) + 1;
876+
return `${selector}:nth-child(${position})`;
877+
}
878+
872879
if (element.className) {
873880
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
874881
if (classes.length > 0) {
@@ -937,6 +944,12 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
937944
function getNonUniqueSelector(element: HTMLElement): string {
938945
let selector = element.tagName.toLowerCase();
939946

947+
if (selector === 'td' && element.parentElement) {
948+
const siblings = Array.from(element.parentElement.children);
949+
const position = siblings.indexOf(element) + 1;
950+
return `${selector}:nth-child(${position})`;
951+
}
952+
940953
if (element.className) {
941954
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
942955
if (classes.length > 0) {
@@ -991,6 +1004,12 @@ export const getChildSelectors = async (page: Page, parentSelector: string): Pro
9911004
function getNonUniqueSelector(element: HTMLElement): string {
9921005
let selector = element.tagName.toLowerCase();
9931006

1007+
if (selector === 'td' && element.parentElement) {
1008+
const siblings = Array.from(element.parentElement.children);
1009+
const position = siblings.indexOf(element) + 1;
1010+
return `${selector}:nth-child(${position})`;
1011+
}
1012+
9941013
const className = typeof element.className === 'string' ? element.className : '';
9951014
if (className) {
9961015
const classes = className.split(/\s+/).filter((cls: string) => Boolean(cls));

0 commit comments

Comments
 (0)