[AHK COM IE] How to get button url Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
g0ss
Posts: 17
Joined: 19 Oct 2018, 11:36

[AHK COM IE] How to get button url

05 Dec 2018, 13:07

Hello,

How to get a button or link URL? href="This value".
IE opens some links in new tab. I want to take URL from a button and navigate to this URL manually. This way it will be on the same tab.

Thanks!
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: [AHK COM IE] How to get button url

05 Dec 2018, 16:14

Can you post the HTML from the page?
g0ss
Posts: 17
Joined: 19 Oct 2018, 11:36

Re: [AHK COM IE] How to get button url

05 Dec 2018, 23:57

sinkfaze wrote:
05 Dec 2018, 16:14
Can you post the HTML from the page?
This is a button from a letter.

Code: Select all

<a class="btn-primary_mailru_css_attribute_postfix" style='border-width: 10px 20px; 
border-style: solid; 
border-color: rgb(19, 175, 240);
margin: 5px 10px 5px 0px;
padding: 0px;
border-radius: 25px; 
border-image: none; 
text-align: center; 
color: rgb(255, 255, 255); 
line-height: 2; 
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; 
font-size: 100%; 
font-weight: bold; 
text-decoration: none; 
display: inline-block; 
cursor: pointer; 
background-color: rgb(19, 175, 240);' 
href="https://www.site.com/token?token=9kupGQXNYpJhbn_MZ5hp" target="_blank" rel=" noopener noreferrer">Button</a>
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: [AHK COM IE] How to get button url  Topic is solved

06 Dec 2018, 01:52

A brief example of what you've tried would help ... but the simple answer is to access the button or link & get the value of it's href property. In accessing the correct button or link, you'll have to identify the element somehow - here's a basic example:

Code: Select all

for window in ComObjCreate("Shell.Application").Windows {
  elements := window.document.getElementsByClassName("btn-primary_mailru_css_attribute_postfix")
  Loop % elements.length {
	e := elements[A_Index - 1]
	
	; Pick what you want to verify
	if (e.tagName = "A") and (e.innerText = "Button") and (e.target = "_blank") and (e.rel = " noopener noreferrer") {
	  element := e
	  break 2
	}
  }
}

MsgBox % element.href
g0ss
Posts: 17
Joined: 19 Oct 2018, 11:36

Re: [AHK COM IE] How to get button url

06 Dec 2018, 04:08

jethrow wrote:
06 Dec 2018, 01:52
In accessing the correct button or link, you'll have to identify the element somehow - here's a basic example:
Thanks for the reply. It helped a lot!
Final script:

Code: Select all

While ( value <> "Button name" ) 
		value := pwb.document.getElementsByTagName( "a")[ A_Index - 1].innerText, index := A_Index - 1 
	elementURL := pwb.document.getElementsByTagName( "a")[ index].href
	Sleep 1000

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], jarhead, mikeyww and 51 guests