IE COM: Getting The placeholder="xxx" text?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kwanbis
Posts: 15
Joined: 10 Apr 2017, 17:07

IE COM: Getting The placeholder="xxx" text?

24 May 2017, 15:19

I am trying to scrape a stupid page that for some reason changes their 2 input fields ID each time it is run... The only thing that stays the same is the placeholder="xxxx" text.

So I was wondering, is there any way to access the "xxx"? Any other ideas?

THANKS!
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 15:40

Maybe you could use the [Element].getAttribute() method, first reducing if necessary the possible matchs taking advantage of [Document].querySelectorAll() - something like that:

Code: Select all

matchingElements := document.querySelectorAll("span.test") ; a first selecting, for example all the span with test as class name
Loop % matchingElements.length
{
	if (matchingElements[a_index-1].getAttribute("placeholder") == "xxxx")
	{
	; ...
	break
	}
}

Hope this helps.
my scripts
User avatar
kwanbis
Posts: 15
Joined: 10 Apr 2017, 17:07

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 15:57

Thanks. So far what I have done is get all the fields (2), and the first returned I assume is the one I want, and is working. I would try your logic latter.

But, maybe you can help me with this. That same page is returning 10 links to subpages, that are like this:
<button data-ember-action="" data-ember-action-10138="10138">2</button>

How can I get them all, so that I can later do elemen.click? wb.document.getElementsByClassName("button") seems wrong somehow.
User avatar
tank
Posts: 3127
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 16:01

hint
document.querySelector("[placeholder='xxx']")
document.querySelectorAll("[placeholder='xxx']")[0]
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
User avatar
kwanbis
Posts: 15
Joined: 10 Apr 2017, 17:07

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 16:06

tank wrote:hint
document.querySelector("[placeholder='xxx']")
document.querySelectorAll("[placeholder='xxx']")[0]
Thanks, would try it.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 16:09

Concerning my first answer you can even try this (supposing the placeholder attribute value behaves like an unique ID):

Code: Select all

MyElement := document.querySelector("[placeholder='xxx']") ; get the first element which has actually an placeholder attribute and whose one is xxx

Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:

Code: Select all

buttons := wb.document.getElementsByTagName("button")

buttons[2].click() ; click the third button of the page

[EDIT] oops too late...

[EDIT] And in case there is a lot of button in your page you can make the research more selective:

Code: Select all

document.querySelectorAll("button[data-ember-action='']")
my scripts
User avatar
tank
Posts: 3127
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 16:23

A_AhkUser wrote:Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
well perhaps but i think you might be mis-underestimating css selectors
document.querySelectorAll("button")[1]
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
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: IE COM: Getting The placeholder="xxx" text?

24 May 2017, 16:48

tank wrote:
A_AhkUser wrote:Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
well perhaps but i think you might be mis-underestimating css selectors
document.querySelectorAll("button")[1]
@Tank no! and that's why my second edit ; I agree, css selectors are more powerfull. However, I suggested it first thinking it could be usefull for kwanbis using it instead: in order to take things into consideration and name the things by their names: tag, class etc. As for me I used getELementById, getELementsByTagName before uisng querySelector (althought it is not the necessary path). For example:

Code: Select all

document.querySelectorAll("button#I[data-ember-action='']")
implies one know that in css stylessheets # is used for IDs while the dot is dedicated for class.

@ Kwanbis The fact that Tank insists on css selector is relevant and should make you consider take a look at it if you deal with webpage (see: css selectors)

Cheers
my scripts
User avatar
kwanbis
Posts: 15
Joined: 10 Apr 2017, 17:07

Re: IE COM: Getting The placeholder="xxx" text?

25 May 2017, 09:08

Thank you both. I would try to make it work today.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, gabelynn1, JoeWinograd, Tech Stuff and 155 guests