Page 1 of 1

[AHK COM IE] How to get button url

Posted: 05 Dec 2018, 13:07
by g0ss
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!

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

Posted: 05 Dec 2018, 16:14
by sinkfaze
Can you post the HTML from the page?

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

Posted: 05 Dec 2018, 23:57
by g0ss
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>

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

Posted: 06 Dec 2018, 01:52
by jethrow
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

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

Posted: 06 Dec 2018, 04:08
by g0ss
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