element selection issue with html dom Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
glen

element selection ahk html dom

21 Jul 2018, 17:05

What I am trying to do is have my code click on text that is in a drop down menu.

I wish I could show you the html code I am referring to but I cannot figure out how to copy and paste from the DOM explorer. I tried downloading the html file and editing it but the formatting was so awful I'd have to spend a long time just to make it readable. I typed up some here.

Code: Select all

<li class="header-menu-level-list-item">
<a class="" data-action="setAgency" data-id="2010">some text here</a>
</li>
I don't know if I have to tell ahk to open up the drop down menu first and then click on the text, or if I can just somehow click on the text without doing that. Manually, I have to click an icon to have the menu appear, and then I click on the text.

I can't figure out how to click on either the icon or the text. Before, with a login button, I was able to do this:

Code: Select all

web_browser.document.getElementsByClassName("login-register-login-submit")[0].click()
I was able to get the Element because it had a class name. The text I need to click on has the class name of "". I tried this:

Code: Select all

web_browser.document.querySelectorAll("")
just to try and select all of the elements with the class name "" and I got an error message.

I need some help.
a) how do I copy and paste html code from DOM Explorer
b) how do I click on the drop down menu with ahk? I'd elaborate more but I can't copy and paste the code.
c) do I need to click on the drop down menu to get to the menu item or can I just get to the menu item without doing that
d) how do I click on the menu item with ahk
glen

element selection issue with html dom

21 Jul 2018, 17:22

I don't know how to copy and paste the html code I'm referring to from DOM explorer, so I'll do my best to describe.

The action I'm trying to automate is hovering over some text to open up a drop down menu and to select on a menu item. The menu disappears if you hover away.

I don't know if I need to automate hovering over text or if I can just select the menu item right away. Does the html code restrict me from going directly there without hovering over text?

Anyway, I just want to click on some text in a menu. Here is that:

Code: Select all

<li class="header-menu-level-list-item">
<a class="" data-action="setAgency" data-id="2010">Some Text Here</a>
</li>
I tried doing this in ahk:

Code: Select all

web_browser.document.querySelectorAll("")
just to be able to select all of the elements with the class name "". This is the third one. I get an error message when I try that. So maybe I have to open up the drop down menu first.

when I hover over the text to open up the menu, the code in html changes from this:

Code: Select all

<div class="" data-toggle="categories-menu">
to this

Code: Select all

<div class="open" data-toggle="categories-menu">
I don't know how to get in there and make it stay open.

Do I need to automate opening the menu first, or can I just through ahk immediately select the menu item? How do I do either?
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: element selection issue with html dom  Topic is solved

21 Jul 2018, 19:43

idea but you dont give much info i can use.

Code: Select all

pwb:=iWeb_NewIe()
iWeb_Nav(pwb,"yourURL")
ele:=iWeb_FindbyText("textoflink",pwb)
ele.click()
	;~ A new internet explorer window
	iWeb_NewIe()
		{
		(pwb := ComObjCreate("InternetExplorer.Application")).Visible:=True
		Return	pwb
		}
	;~ Navigate to a url
	iWeb_Nav(pwb,url)						; returns bool 
		{
		If  (!pwb || !url)		;	test to see if we have a valid interface pointer
			{
			MsgBox, 262160, Browser Navigation, The Browser you tried to Navigate to `n%url%`nwith is not valid
			Return						;	ExitApp if we dont
			}
	;~ 	
	;~ 	http://msdn.microsoft.com/en-us/library/aa752133(VS.85).aspx
		navTrustedForActiveX	=	0x0400
		pwb.Navigate(url,	navTrustedForActiveX,	"_self")
		iWeb_complete(pwb)
		Return							;	return the result(bool) of the complete function 
		}									;	nav function end
	;~ wait for a page to finish loading
	iWeb_complete(pwb)						;	returns bool for success or failure
	{	
		while !pwb.busy
			Sleep 1
		while pwb.busy
			sleep 1		
		while pwb.readystate != 4
			sleep 1				
	}		
						;	end complete
	;~ get the window onject from an object
	iWeb_DomWin(pdsp,frm="")
		{
		If	pWin	:=	IHTMLWindow2_from_IWebDOCUMENT( pdsp ) 
			{
			Loop, Parse, frm, `, 
				{
				frame:=pWin.document.all.item[A_LoopField ].contentwindow
				ObjRelease(pWin)
				pWin:=IHTMLWindow2_from_IWebDOCUMENT( frame )
				ObjRelease(frame)
				If	!pWin
					Return	False
				}
			Return	pWin
			}	
		Return False
		}
	IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT )
		{
		static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"  ; IID_IHTMLWindow2
		return ComObj(9,ComObjQuery( IWebDOCUMENT, IID_IHTMLWindow2, IID_IHTMLWindow2),1)
		}	
	;~ iWeb_FindbyText(needle,win="A",property="",offset=0,frm="")
	iWeb_FindbyText(needle,pwb,offset=0,frm="")
		{
		If	pWin	:=	iWeb_DomWin(pwb,frm) 
			{
			If	oRange:=pWin.document.body.createTextRange
				{
				oRange.findText(needle)
				_res:=pWin.Document.all.item[ oRange.parentElement.sourceIndex+offset]
				ObjRelease(oRange)
				}	
			}
		Return	_res
		}
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
glen

Re: element selection issue with html dom

22 Jul 2018, 11:03

I apologize. I'm new at AHK and this code just went over my head.

What information could I give to better describe the problem? I posted another form question with a more accurate description of the problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: coder96, gongnl, Joey5, RandomBoy and 340 guests