SOLVED: Trouble accessing one object via DOM on webpage

Get help with using AutoHotkey and its commands and hotkeys
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

SOLVED: Trouble accessing one object via DOM on webpage

03 Aug 2015, 17:56

I’ve been working with DOM to be able to automatically populate the fields on a web page (see screen capture #1). I used iWB2 Learner to get the names of the fields and it is going well, and I have been able to access and populate/write all the input fields, such as:
(using wb := IEGet("Calendar - Bookeo") from Jethreow)

Code: Select all

wb.Document.All.cardType.Value := "VISADEBIT"   
wb.Document.All.cardNumber.Value := "1234123412341234"
wb.Document.All.cardHolderName.Value := "John Smith"
wb.Document.All.expiryMonth.Value := "12"
wb.Document.All.expiryYear.Value := "2021"
wb.Document.All.cvv.Value := "999"
However, I am trying to access/read the “dueNow” element (screen capture #2) via:

Code: Select all

var1 := wb.Document.All.dueNow.value
but have been unsuccessful.

Whereas this works:

Code: Select all

var1 := wb.Document.All.cardHolderName.Value
QUESTION: Is there a different way to read static text elements vs. input elements? Or is it because it is in a different part of the page (maybe a different form)? Or something else I am doing wrong? Thanks!
Attachments
Screen-02.jpg
Screen-01.jpg
Last edited by momo2000 on 04 Aug 2015, 13:27, edited 3 times in total.
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: Trouble accessing one object via DOM on webpage

03 Aug 2015, 20:54

I keep searching and looking at examples, and I think this might be an "innertext vs. value" thing. I've been successful at getting a Value from an INPUT, but a TEXTAREA(what I think that might be) (it is part of a table) might use INNERTEXT to get the value from it. Still struggling with the exact syntax to get it.
User avatar
boiler
Posts: 3284
Joined: 21 Dec 2014, 02:44

Re: Trouble accessing one object via DOM on webpage

04 Aug 2015, 00:49

You should be able to just replace value with innerText.

You might also try wb.Document.forms[0].elements[9].value, where you would replace 9 with different values from 0 to whatever until you've idenified the right item on the form. It doesn't have to be a form element like an edit box in order to be considered one of the elements in this context. If it's a form, which it seems this is, every element on the page seems to be an element of it. It's just the matter of finding the right number.
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: Trouble accessing one object via DOM on webpage

04 Aug 2015, 09:50

boiler: Thanks, you are exactly right:

Code: Select all

var1 := wb.Document.All.dueNow.innerText
worked flawlessly. Sometimes things are so simple, but you gotta get they syntax right . . . thanks for the assist and ending my hours of frustration!!!!! :D
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: SOLVED: Trouble accessing one object via DOM on webpage

04 Aug 2015, 10:07

Strange, now it doesn't work?????? It absolutely was working.
User avatar
sinkfaze
Posts: 613
Joined: 01 Oct 2013, 08:01

Re: Trouble accessing one object via DOM on webpage

04 Aug 2015, 11:21

Are you using the tool to check and make sure the field has the same attributes as before when it fails?
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: Trouble accessing one object via DOM on webpage

04 Aug 2015, 13:27

Well, I keep reading the forums and was able to grab it another way:

Code: Select all

var1 :=wb.document.getElementsByTagName( "div")[ 42].innerText
Finding some other articles on the forums, I had "looped" through to get the element number.
So that solved it. Still strange about it working then not working, but it seems to be reliable now.
User avatar
sinkfaze
Posts: 613
Joined: 01 Oct 2013, 08:01

Re: SOLVED: Trouble accessing one object via DOM on webpage

04 Aug 2015, 15:06

Be careful with that method, if the elements on the page are dynamic that index number will change and you'll pull the wrong thing (or nothing at all).
User avatar
boiler
Posts: 3284
Joined: 21 Dec 2014, 02:44

Re: SOLVED: Trouble accessing one object via DOM on webpage

04 Aug 2015, 15:59

Yeah, I've had issues like that, but I was able to account for them because the changes were predictable since my script was controlling the page and causing more items to be added in a known fashion.
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: SOLVED: Trouble accessing one object via DOM on webpage

04 Aug 2015, 16:46

Thanks sinkfaze. Agreed, that could be a problem, but actually that page "shouldn't" (famous last words) change. It was the only way I could get it working. Thanks for the help.

Return to “Ask For Help”

Who is online

Users browsing this forum: agrout, Bad husband, densch, Flipeador, FrostByte and 62 guests