Send to element in web-page

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BitcoinVirus
Posts: 18
Joined: 31 Jan 2019, 11:21

Send to element in web-page

14 Sep 2019, 20:39

Can this be changed to Google chrome? I can't seem to figure out how to make this work for logging into Instagram.

Code: Select all

WB := ComObjCreate("InternetExplorer.Application")
WB.Visible := True
WB.Navigate("https://www.instagram.com/") 
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10

wb.document.getElementById("username").value := "test"
wb.document.getElementById("clear").value := "test"
   
return
gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: Send to element in web-page

15 Sep 2019, 01:34

Your question 'Can this be changed?' seemed to imply that this code above actually currently works with IE COM and the Instagram website... but the IDs seem to be wrong, among other problems.

You could still try to use Chrome.ahk or the Selenium Webdriver (afaik, both will have to start your Chrome browser in debugging mode, but that's not so bad.).

This is some Chrome.ahk code that will "fill" the boxes for username and password, but I don't think that the Instagram login interface actually fancies automation like this, as it doesn't seem to react properly to this kind of actions (the text appears in the boxes, but the prompts/cue banners don't move out of the way like they would during actual human input).
I can't really test it since I don't use Instagram, but I think the whole javascript-react.js-stuff on the login page won't allow you to actually login this way:

Code: Select all

#NoEnv
#Include chrome.ahk			; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890
SetBatchLines, -1
SetTitleMatchMode 2

url := "https://www.instagram.com/"

; --- Create a new Chrome instance ---
FileCreateDir, ChromeProfile
Browser := new Chrome("ChromeProfile")
WinWait, Chrome

; --- Connect to the page ---
Page := Browser.GetPage()
Page.Call("Page.navigate", {url : url})

Page.waitForLoad()
while !success
{
	try 
		if (Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP');") != "")
			success := true
	sleep 250
}
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[2].value = 'test';")
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[3].value = 'testpass';")
So what are the alternatives? Well, afaik, Chrome.ahk (and Selenium, I think) also offers ways to simulate "trusted" keystrokes/inputs - but at the moment, I don't have the time to whip out an example; and it might work or not... I could try later, though.

The Instagram API, which exists, seems to be mainly for registered app developers.

Of course, you could try some old-style tabbing and sending... or perhaps the Acc.ahk library could help, but I am not very familiar with it.

Perhaps I also missed some other alternative :think:.
But my guess is that this kind of automation is not ok with Instagram's terms of service. So whatever you do, make sure that you don't get banned :shifty:

Edit: The best way to login is probably to let Chrome (or some plugin) save and then autofill your user credentials for Instagram, like you could as a human user (if that works on the Instagram login site).
With Chrome.ahk (or to be more precise: the Chrome debugging protocol) it is actually possible to always use the same user profile and make use of 'remember me' cookies etc... that's much better/easier than on IE. But make sure that you really login on the specific user profile that you then use with Chrome.ahk.
Of course, further (legitimate ;) ) automation of the website would still need some work with Chrome.ahk (or Selenium or whatever).
User avatar
BitcoinVirus
Posts: 18
Joined: 31 Jan 2019, 11:21

Re: Send to element in web-page

15 Sep 2019, 14:11

Code: Select all

#NoEnv
#Include chrome.ahk
SetBatchLines, -1
SetTitleMatchMode 2
url := "https www.instagram.com /"  Broken Link for safety
FileCreateDir, ChromeProfile
Browser := new Chrome("ChromeProfile")
WinWait, Chrome
Page := Browser.GetPage()
Page.Call("Page.navigate", {url : url})
Page.waitForLoad()
while !success
{
	try 
		if (Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP');") != "")
			success := true
	sleep 250
}
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[0].value = 'email.gmail.com';")
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[1].value = 'this is name';")
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[2].value = 'myusername';")
Page.evaluate("document.querySelectorAll('input._2hvTZ.pexuQ.zyHYP')[3].value = 'password123';")
This is meant for signing up an account, but there seems to be an issue when the signup bottom is executed. All the imputed information clears.

Sorry for my poor English
gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: Send to element in web-page

15 Sep 2019, 14:22

That's what I expected - oh yeah, that page is for signing up, not logging in. I didn't read it thoroughly :) .

But signing up new accounts automatically will be against Instagram's terms of service for sure... you surely intend to create a multitude of accounts :problem:, and not just one :!:

Just signing in to an existing account, ok, I can understand the need for it - but I told you what I would do (autofill).

But creating new accounts automatically - this doesn't sound legit (but rather spammy) and I personally would consider that outside the scope of help we can and want to provide in this forum... if I understood correctly, I would consider any code for something like this potentially malicious and harmful to our forum's reputation.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mamo691 and 222 guests