Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

search a button on a web page and click on it ?


  • Please log in to reply
4 replies to this topic
stephabc
  • Members
  • 7 posts
  • Last active: Mar 15 2015 10:15 PM
  • Joined: 23 May 2014

Hello,

 

I would like to find the button on a web page that says for example 'Enter" and when found on the page click on it ?

do you know  way to do it ?

 

Thanks for your help

Br,

Stéphane

 



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
http://ahkscript.org...c.php?f=7&t=427
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

stephabc
  • Members
  • 7 posts
  • Last active: Mar 15 2015 10:15 PM
  • Joined: 23 May 2014

Thanks i will try that !

Br,

Stéphane



13921
  • Members
  • 31 posts
  • Last active: Sep 21 2015 03:25 AM
  • Joined: 30 May 2014

I use 2 methods to do this in Firefox.


1:        Press tab to navigate webpage elements.

                Handy if the button is within 10 Tabs, otherwise it feels silly.

 

 

2:        Activate the button/focus it via javascript.

                Reliable, just need to get the element ids. Just make sure javascript is enabled in your browser!

 

 

Method 1 is easy enough to sort out on it's own. Here's an example of Method 2 and how to use it:

        This example uses http://www.autohotkey.com/board/

At the bottom of the page we have displayed users currently online. Let's say we need to open the profile of whatever the first name is of that list.

 

Step 1, Right click the first name under where it says "# members, # guests, # anonymous users (See full list)".

        In my case it's my username so I'll assume it will be your own if you're signed in. Click Inspect element.

 

Step 2, Look for something that says, id="copy_this_text" For this example it was anonymous_element_15

       You'll be able to tell here if the item in question is a button.

 

Step 3, Paste the id without quotes into this: javascript:document.getElementById("paste_text_here").focus()

        You can test it out by just pasting the underlined text into your browsers url.

 

 

Below is a fully functional example.

The function TabCheck isn't used, but it can come in handy for error checking. TabCheck ensures you went to the right place, or checks to see if you haven't gone to the next webpage yet. It does not ensure that the webpage you're on is fully loaded.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
/*
Firefox navigation example
Start here: http://www.autohotkey.com/board/
*/

Java(paste)						;executes javascript in url bar
{
	Clipboard =
	Clipboard := paste
	ClipWait, 1
	Sleep 10
	Send {F6}			;default key to focus the url in firefox
	Sleep 50
	Send javascript:
	Sleep 50
	Send ^v
	Sleep 50
	Send {Enter}
	Sleep 120
}

TabCheck(name)			;check for being on the right webpage, useful if you know where you're supposed to be
{						;mouse-over the tab title to get it's name
	WinGetActiveTitle, starttitlevar
	Sleep 1000
	ifWinActive, %name%
	{				;next webpage is open
		Sleep 500
		;msgbox, %name% is active window`n%starttitlevar% was start title ;`n ignore this
		;msgbox, Press enter when the page has loaded.		;sometimes needed for heavy/sporadic loading times
	}
	
	else
	{				;next webpage not open yet
		Sleep 1000			;adjust this to your needs
		TabCheck(%name%)
	}
}

;	example id
;anonymous_element_15

;	use for buttons
;__doPostBack('','')

;	use for links/input fields
;document.getElementById("").focus()

pressit = __doPostBack('anonymous_element_15','')	
focusit = document.getElementById("anonymous_element_15").focus()

;insert key
Ins::
Java(focusit)
Send {Enter}
return





smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012

For Chrome use Tampermonkey extensions

For Firefox they say there is Greasemonkey add-on

 

write a script. 

use settimeout, setinterval, clearinterval commands ( javascript ) in addition with .click() etc.

 

I have made something exactly for this purpose. In case you are still around please tell details. that is The Inspect Element etc.