I've been messing with the chrome class and I'll happily admit my js syntax is nil to none. I'm just trying to create a simple serach to find a specific element I'm looking for and grab the adjacent element or +1 from that. I've got it working in IE DOM but for the past two days of JS research I'm still scratching my head. I was hoping someone could help me out and give me an example to run with.
Here is my IE DOM script that worked on my page to find the tag element with "Modem MAC:" and then grab the innertext which is the next element over.
Code: Select all
All:=WB.Document.GetElementsByTagName("Span") ;Get Tagname and Array value
while(aa:=All.Item[A_Index-1]){
if(aa.InnerText="Modem MAC:"){ ;*[Grab Info from Gateway]
msgbox % aa.ParentNode.GetElementsByTagName("Span").Item[1].InnerText
}
}
I came up with this chrome code to grab the element and return it to me. So I know I can target the element next to the one I need, I just need to grab the next element over from this one:
Code: Select all
PageInst.Evaluate("document.getElementsByTagName('Span').textContent='Modem MAC:'"))
I'm struggling with the syntax of getting the A_Index-1 to work properly. I thought of doing a LOOP through all spans (1474 on my work page I'm doing this through) and finding Modem MAC: then grabbing +1 span element after textContent. However, I got even more confused about how to enter the A_Index loop counter. Reason being this way is because the only anchor I have on the page is the text "Modem MAC:"... otherwise the span number always changes and it has no concreate class ID as that changes too.
Thoughts?
Edit -- I was able to finally figure out how to loop through each element. But still having trouble getting my desired result. But here is the loop I came up with.
Code: Select all
while(PageInst.Evaluate("document.getElementsByTagName('div')['" A_Index "']")){
MsgBox, % PageInst.Evaluate("[].filter.call(document.querySelectorAll('span'), e=>e.innerText=='Modem MAC:')[0].nextSibling.querySelector('div').innerText").value
}
Edit#2 -- After a week of tackling this I've gotten really damn close but I think my syntax is slightly wrong. The code below works on IE
Code: Select all
WB := WBGet()
while(WB.Document.GetElementsByTagName("Span").Item[A_Index-1]){
if(WB.Document.GetElementsByTagName("Span").Item[A_Index-1].InnerText="Modem MAC:"){ ;*[Grab Info from Gateway]
msgbox % WB.Document.GetElementsByTagName("Span").Item[A_Index-1].nextSibling.GetElementsByTagName("Div")[0].innerText
}
}
This is my attempt at changing the syntax and could use another pair of eyes as what I'm not correctly translating?
Code: Select all
Tab:=PageInst
while(Tab.Evaluate("document.getElementsByTagName('Span')['" A_Index "']")){
if(Tab.Evaluate("document.getElementsByTagName('Span')['" A_Index "'].innerText='Modem MAC:'")){
msgbox % Tab.Evaluate("document.getElementsByTagName('Span')['" A_Index "'].nextSibling.getElementsByTagName('Div')[0].innerText").Value
}
}
Solved: Thank you Geekdude for pointing me in the right direction, using JS to search for it and convert back to ahk.
Code: Select all
MsgBox, % PageInst.Evaluate("[].filter.apply(document.querySelectorAll('.span'), e=>e.innerText=='Modem Mac:')[0].nextSibling.querySelector('div').innerText").value