-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathxPath.ts
More file actions
48 lines (43 loc) · 1.63 KB
/
Copy pathxPath.ts
File metadata and controls
48 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Returns all elements containing text without case matching
* @param text the text to match
* @param tag Tag containing the text
* @param nth Number of the tag, if there are more then one
* @param allowWrapped Whether there could be other element in the path
* @returns {string}
*/
export const getAnyContainingText = (
text,
tag = '*',
nth = 1,
allowWrapped = true
) =>
`//${tag}${
allowWrapped ? '/descendant-or-self::*' : ''
}/text()[contains(translate(.,` +
`'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '${text.toLowerCase()}')][${nth}]/parent::*`;
export const getAnyContainingAriaLabelAttribute = (
text,
tag = '*',
nth = 1,
allowWrapped = true
) =>
`//${tag}${allowWrapped ? '//*' : ''}[contains(translate(@aria-label,` +
`'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '${text.toLowerCase()}')][${nth}]`;
export const getInput = (name, nth = 1) =>
`//input[translate(@name,` +
`'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = '${name.toLowerCase()}'][${nth}]`;
export const getTextArea = (name, nth = 1) =>
`//textarea[translate(@name,` +
`'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = '${name.toLowerCase()}'][${nth}]`;
export const getClosestContainingText = (text, tag = '*', nth = 1) =>
`./ancestor::*[.//*[${containsIgnoreCase(
'text()',
text
)}]][1]//*[contains(text(), "${text}")]`;
export const containsIgnoreCase = (
pathElementToContain: string,
toBeContained: string
) => {
return `contains(translate(${pathElementToContain}, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '${toBeContained.toLowerCase()}')`;
};