-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.txt
74 lines (57 loc) · 2.47 KB
/
info.txt
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
protected String getXPath() {
String jscript = "function getPathTo(node) {" +
" var stack = [];" +
" while(node.parentNode !== null) {" +
" stack.unshift(node.tagName);" +
" node = node.parentNode;" +
" }" +
" return stack.join('/');" +
"}" +
"return getPathTo(arguments[0]);";
return (String) driver.executeScript(jscript, webElement);
}
def tester(elem):
for t in elem:
driver.execute_script("""gPt=function(c){
if(c.id!==''){
return'id("'+c.id+'")'
}
if(c===document.body){
return c.tagName
}
var a=0;
var e=c.parentNode.childNodes;
for(var b=0;b<e.length;b++){
var d=e[b];
if(d===c){
return gPt(c.parentNode)+'/'+c.tagName+'['+(a+1)+']'
}
if(d.nodeType===1&&d.tagName===c.tagName){
a++
}
}
};
return gPt(arguments[0]).toLowerCase();""", t)
var element = $( "a:contains('SearchingText')" );
for (const a of document.querySelectorAll("a")) {
if (a.textContent.includes("your search term")) {
console.log(a.textContent)
}
}
Or with a separate filter:
[...document.querySelectorAll("a")]
.filter(a => a.textContent.includes("your search term"))
.forEach(a => console.log(a.textContent))
function getElementsByText(str, tag = 'a') {
return Array.prototype.slice.call(document.getElementsByTagName(tag)).filter(el => el.textContent.trim() === str.trim());
}
Usage
getElementsByText('Text here'); // second parameter is optional tag (default "a")
if you're looking through different tags i.e. span or button
getElementsByText('Text here', 'span');
getElementsByText('Text here', 'button');
const callback = element => element.innerHTML == 'My research'
const elements = Array.from(document.getElementsByTagName('a'))
// [a, a, a, ...]
const result = elements.filter(callback)
console.log(result)