works great, most cases I use a script to get data from there but sometimes I need something quick, for some results, this is great,burque505 wrote: ↑01 Jul 2020, 07:09@AHKStudent, this will get your data, just tried it. But it contains newlines, so you'll have to transform the data to get rid of them.
Regards,Code: Select all
selector := "'div.table-list-item'"
burque505
Detect clickable link in Chrome
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Detect clickable link in Chrome
Re: Detect clickable link in Chrome
Glad to hear it!
Regards,
burque505
Regards,
burque505
Re: Detect clickable link in Chrome
Is this supposed to work for non-emails too, like random websites? I cannot get it to click the link that contians specific word. The URL just flashes. Using latest chrome.teadrinker wrote: ↑05 May 2020, 08:17If using accsessible, it's easier to get acc-object of Chrome address bar and run javascript from it, which searches for a link with specified text and clicks it.Code: Select all
SetBatchLines, -1 linkText := "05 May 2020, 06:43" js = ( (() => { const links = document.links; for (let i = 0; i < links.length; i++) { if (links[i].innerText == '%linkText%') { links[i].click(); break } } })(); ) $F1:: RunJsFromChromeAddressBar(js) RunJsFromChromeAddressBar(js, exe := "chrome.exe") { static WM_GETOBJECT := 0x3D , ROLE_SYSTEM_TEXT := 0x2A , STATE_SYSTEM_FOCUSABLE := 0x100000 , SELFLAG_TAKEFOCUS := 0x1 if !AccAddrBar { window := "ahk_class Chrome_WidgetWin_1 ahk_exe " . exe SendMessage, WM_GETOBJECT, 0, 1, Chrome_RenderWidgetHostHWND1, % window AccChrome := AccObjectFromWindow( WinExist(window) ) AccAddrBar := SearchElement(AccChrome, {Role: ROLE_SYSTEM_TEXT, State: STATE_SYSTEM_FOCUSABLE}) } AccAddrBar.accValue(0) := "javascript:" . js AccAddrBar.accSelect(SELFLAG_TAKEFOCUS, 0) ControlSend,, {Enter}, % window, Chrome Legacy Window } SearchElement(parentElement, params) { found := true for k, v in params { try { if (k = "ChildCount") (parentElement.accChildCount != v && found := false) else if (k = "State") (!(parentElement.accState(0) & v) && found := false) else (parentElement["acc" . k](0) != v && found := false) } catch found := false } until !found if found Return parentElement for k, v in AccChildren(parentElement) if obj := SearchElement(v, params) Return obj } AccObjectFromWindow(hWnd, idObject = 0) { static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}" , IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}" , OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1 , h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr") VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF DllCall("ole32\CLSIDFromString", "Str", idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, "Ptr", &IID) if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject, "Ptr", &IID, "PtrP", pAcc) = 0 Return ComObject(VT_DISPATCH, pAcc, F_OWNVALUE) } AccChildren(Acc) { static VT_DISPATCH := 9 Loop 1 { if ComObjType(Acc, "Name") != "IAccessible" { error := "Invalid IAccessible Object" break } try cChildren := Acc.accChildCount catch Return "" Children := [] VarSetCapacity(varChildren, cChildren*(8 + A_PtrSize*2), 0) res := DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(Acc), "Int", 0 , "Int", cChildren, "Ptr", &varChildren, "IntP", cChildren) if (res != 0) { error := "AccessibleChildren DllCall Failed" break } Loop % cChildren { i := (A_Index - 1)*(A_PtrSize*2 + 8) child := NumGet(varChildren, i + 8) Children.Push( (b := NumGet(varChildren, i) = VT_DISPATCH) ? AccQuery(child) : child ) ( b && ObjRelease(child) ) } } if error ErrorLevel := error else Return Children.MaxIndex() ? Children : "" } AccQuery(Acc) { static IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}", VT_DISPATCH := 9, F_OWNVALUE := 1 try Return ComObject(VT_DISPATCH, ComObjQuery(Acc, IAccessible), F_OWNVALUE) }
-
- Posts: 4400
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Detect clickable link in Chrome
Try replacing with
Code: Select all
links[i].click();
Code: Select all
window.location = links[i].href;
Re: Detect clickable link in Chrome
I actually got it to work with the original, and the replacement too.teadrinker wrote: ↑01 Mar 2023, 20:26Try replacingwithCode: Select all
links[i].click();
Code: Select all
window.location = links[i].href;
I know why it wasn't working, I think: It seems to only work when that particular string only occurs once in current viewing window. The words I was looking for existed twice so it didn't word. So if the word/phrase exists twice or more in that window, the script wont click on it. I guess it gets confused? Anyway to fix this? Like, make it click the first instance that word link that it finds?
Last edited by samt on 01 Mar 2023, 20:44, edited 1 time in total.
-
- Posts: 4400
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Detect clickable link in Chrome
Interesting. Not sure why it doesn't work for me if there's 2 of the same words. Trying it this AHK forum and it doesn't click anything if that word/phrase appears twice? (they lead to same URL)teadrinker wrote: ↑01 Mar 2023, 20:42No, in this case the script should click on the first link it finds.
-
- Posts: 4400
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Detect clickable link in Chrome
For me this correctly works on this page: linkText := "samt"
Re: Detect clickable link in Chrome
You're right, that works. I noticed it seems to lead to a different link than when you click on it manually.
Try this:
Code: Select all
linkText := "Re: Detect clickable link"
-
- Posts: 4400
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Detect clickable link in Chrome
The complete text is "Re: Detect clickable link in Chrome".
Re: Detect clickable link in Chrome
It seems to work. I tried it on some other sites but it doesn't seem to work..
Anyways, I'll pause trying for now. Not sure what's going on, but got some other stuff to do. Thanks for the help!