Page 1 of 1

SOLVED: Trouble accessing one object via DOM on webpage

Posted: 03 Aug 2015, 17:56
by momo2000
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!

Re: Trouble accessing one object via DOM on webpage

Posted: 03 Aug 2015, 20:54
by momo2000
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.

Re: Trouble accessing one object via DOM on webpage

Posted: 04 Aug 2015, 00:49
by boiler
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.

Re: Trouble accessing one object via DOM on webpage

Posted: 04 Aug 2015, 09:50
by momo2000
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

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

Posted: 04 Aug 2015, 10:07
by momo2000
Strange, now it doesn't work?????? It absolutely was working.

Re: Trouble accessing one object via DOM on webpage

Posted: 04 Aug 2015, 11:21
by sinkfaze
Are you using the tool to check and make sure the field has the same attributes as before when it fails?

Re: Trouble accessing one object via DOM on webpage

Posted: 04 Aug 2015, 13:27
by momo2000
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.

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

Posted: 04 Aug 2015, 15:06
by sinkfaze
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).

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

Posted: 04 Aug 2015, 15:59
by boiler
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.

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

Posted: 04 Aug 2015, 16:46
by momo2000
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.