문제

I'm new to scripting. I am trying to automate some web form filling tasks.

I was able to do most parts where there was as HTML "ID" tag assigned.

For instance,

If the form has this:

<input type="text" maxlength="30" size="30" value=" " name="desc" id ="id1"></input>

I used something like below code to assign a value to the Textbox.

oIE.Document.All.Item("id1").Value = "MESSIAH1"

However, there are some forms that I am handling that have (code below):

<input type="text" maxlength="30" size="30" value=" " name="desc"></input>

No "Id" , just "name"

What do we do here ? Any pointers? In general, my question is how would I fill / access forms (elements) when I dont have an associated HTML "ID" , but just a "name" .

Appreciate all help

*If it matters, I'm running VBSCRIPT on IE8 .

Merci beaucoup!

도움이 되었습니까?

해결책

getElementsByName returns an HTMLCollection. You can access the value of the first item like this:

document.getElementsByName("desc").item(0).value

Or like this:

document.getElementsByName("desc")[0].value

More info: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection

Font: Using document.getElementsByName() isn't working?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top