Xeo786 / Rufaydium-Webdriver

GNU General Public License v3.0
10 stars 1 forks source link

Based on your inspiration and code, I made some improvements. #6

Open telppa opened 1 month ago

telppa commented 1 month ago

https://github.com/telppa/Chrome.ahk-plus

Significantly simplifies the manipulation of elements and frames.

I don't know how to merge these improvements into your project, but maybe you're interested as well.

alt text

Example for TAB/Page 1

PageInst.SwitchToFrame(1)       ; switching to frame A
PageInst.GetElementById(someid) ; this will get element from frame A
PageInst.SwitchToFrame(2)       ; switching to frame B
PageInst.GetElementById(someid) ; this will get element from frame B
PageInst.SwitchToFrame(2, 1)    ; switching to frame BA
PageInst.GetElementById(someid) ; this will get element from frame BA
PageInst.SwitchToFrame(2)       ; switch back to Frame B
PageInst.SwitchToMainPage()     ; switch back to Main Page / Main frame

Example for TAB/Page 1

PageInst.SwitchToFrame(1)            ; switching to frame A
PageInst.GetElementById(someid)      ; this will get element from frame A
PageInst.SwitchToFrameByName("B")    ; switching to frame B by name
PageInst.GetElementById(someid)      ; this will get element from frame B
PageInst.SwitchToFrameByURL(urlOfBA) ; switching to frame BA by url
PageInst.GetElementById(someid)      ; this will get element from frame BA
PageInst.SwitchToFrame(2)            ; switch back to Frame B
PageInst.SwitchToMainPage()          ; switch back to Main Page / Main frame
Xeo786 commented 1 month ago

Thank you. I would have implemented frame switching from CDP but webdriver has it own apis to deal with them bit complicated but the issue is when you switch the frame from CDP it is not switched for driver we can target specific frame by using CDPcall and extract frame tree. but not all web pages designed same.

btw Long ago when I was learning AHK classes I worked on Devtool protocols Chrome.ahk DOM Wrapper, It has the ability to get the whole tree of frame you might find it useful, there I just try to simplyfy the chrome.ahk use for example

Page := chrome.GetPageByURL("https://webflow.com/blog/business-website-examples","contains")
Document := New DOM(Page)
id := "w-node-_924b83c0-f4ca-a978-eee8-5ff56c41a20f-b19772d1"
e := Document.getelementbyid(id)
msgbox, % "TextContent:`n" e.TextContent "`n`nInnerText:`n" e.InnerText
e := e.querySelector("h1")
e.InnerText := "123456" ; setting new innerText 
telppa commented 1 month ago

thank you.

i have a new question, this is your code in cdp.ahk

        Frame(i)
    {
        frameId := this.childFrames[i +1].frame.id
        this.ParentNodeID := this.Nodeid
        if frameId
        {
            nodeid := this.call("DOM.getFrameOwner",{"frameId":frameId}).nodeid
            backendNodeId := this.call("DOM.describeNode",{"nodeId":nodeid}).node.contentDocument.backendNodeId
            contentDocObject := this.call("DOM.resolveNode",{"backendNodeId":backendNodeId}).object.objectId
            this.nodeid := this.call("DOM.requestNode",{"objectId":contentDocObject}).nodeId
        }   
    }
    Frame(i)
    {
        frameId := this.childFrames[i +1].frame.id
        this.ParentNodeID := this.Nodeid
        if frameId
        {
            this.nodeid := this.call("DOM.getFrameOwner",{"frameId":frameId}).nodeid
        }   
    }

I experimented and found that the first method of getting the frame's nodeid was correct, but I couldn't understand why the second method of getting the nodeid wouldn't work properly.

Xeo786 commented 1 month ago

I am not professional I just read chome Devtool protocols and figure that out, and this is what I understand.

there DOM inside a DOM both dom has their own nodeId, first method reading the frame id and then approaches to the DOM inside and get document (contentDocument) nodeid within the frame,

see backendNodeId := this.call("DOM.describeNode",{"nodeId":nodeid}).node.contentDocument.backendNodeId there is 'contentDocument' which does not offer nodeid so we inquire for objectid using backendnodeid and from object id we inquire and get the nodeid

second method its get the nodeid of that frame ....