Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting element with no ID specified

Status
Not open for further replies.

JairIrwin

Technical User
Apr 8, 2012
4
CA
Hello,

We have successfully used the script listed below to check/select various items on a webpage (Website1), and then search. This is repeated every 15 minutes. Everything works great.

However, on a different, older version of the website (Website2), which we also need to manipulate, this code does not work because the fields in the loop – statusF, statusFS, optL12H – do not exist. These are IDs, but in the other version of the website, the ID fields simply don’t exist.

Here is what I mean.

Website 1:
input type="checkbox" name="status" value="0" id="statusA" /><img title="Transfer in Progress" src="/coreadmin/images/common/in_progress2.gif"/>
&nbsp;&nbsp;
<input type="checkbox" name="status" value="2" id="statusF" /><img title="Transfer Failed" src="/coreadmin/images/common/failed_16.gif"/>
&nbsp;&nbsp;
<input type="checkbox" name="status" value="3" id="statusFS" /><img title="Failed Subtransmission" src="/coreadmin/images/common/icon_pta_failure.gif"/>

Website 2 (same as above, but with no IDs specified)
<input type="checkbox" name="status" value="0" /><img title="Transfer in Progress" src="/coreadmin/images/common/in_progress2.gif"/>
&nbsp;&nbsp;
<input type="checkbox" name="status" value="2" /><img title="Transfer Failed" src="/coreadmin/images/common/failed_16.gif"/>
&nbsp;&nbsp;
<input type="checkbox" name="status" value="3" /><img title="Failed Subtransmission" src="/coreadmin/images/common/icon_pta_failure.gif"/></td></tr>

We cannot change the code of the websites because they do not belong to us. Is there anything we can do? How can we specify if no ID is present? The “name” field is the same for several (not unique). Any input would be appreciated.

Script that works on Website1, but not Website2:

Set IE = CreateObject("InternetExplorer.Application")
set WshShell = CreateObject("WScript.Shell")
IE.Navigate " IE.Visible = True
WScript.Sleep 10000

Do While True
WScript.Sleep 150000
IE.Document.All.Item("statusF").Checked = true
IE.Document.All.Item("statusFS").Checked = true
IE.Document.All.Item("optL12H").Selected = true
IE.Document.All.Item("search").Click()
Loop
 
Try something like this:
IE.document.getElementsByName("statusF")(0).Checked = true
 
Hi Guitarzan,

Wow, thanks very much! That solved the riddle. I'm able to get the check boxes checked without having an ID! Really appreciate the tip.

We're still struggling with one other part of the script. It relates to a drop down list, which is a bit different from the checkbox.

Website 1:
</select></td><td align="center" width="20">in</td><td nowrap="nowrap"><select onchange="changeDateFilter(this);" name="timePeriod" id="timePeriod"><option value="0" id="optLastHour">Last Hour</option><option value="1" id="optLast4Hours">Last 4 Hours</option><option value="2" id="optLast8Hours">Last 8 Hours</option><option selected="selected" value="3" id="optLast12Hours">Last 12 Hours</option><option value="4" id="optLast24Hours">Last 24 Hours</option><option value="5" id="optLast48Hours">Last 48 Hours</option><option value="6" id="optLastWeek">Last 1 Week</option><option value="7" id="optLast2Week">Last 2 Weeks</option><option value="8" id="optSpecificDate">Specific Date/Time Range...</option></select>

Website 2 (same as above, but no IDs specified):
</select></td><td align="center" width="20">in</td><td nowrap="nowrap"><select onchange="changeDateFilter(this);" name="timePeriod"><option value="0">Last Hour</option><option value="1">Last 4 Hours</option><option value="2">Last 8 Hours</option><option selected="selected" value="3">Last 12 Hours</option><option value="4">Last 24 Hours</option><option value="5">Last 48 Hours</option><option value="6">Last 1 Week</option><option value="7">Last 2 Weeks</option><option value="8">Specific Date/Time Range...</option></select>

Code that works with Website 1, but not Website 2:
IE.Document.All.Item("optLast12Hours").Selected = true

Any idea on what code we can use if no IDs are present in this case?

Thanks!

Jair.

 
you can get all the option fields and reference them against the text. Not sure on the extact syntax but here's a start.

untested and conceptual
Code:
strSelect = "optLast12Hours"
set objOptions = document.getElementsByTagName("option")
for each objOption in objOptions
   if (objOption.text = strSelect) then
      objOption.selected = true
   end if
next

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for the help everyone. We were able to get our automation working thanks to the help of the posters here.

Jair.
 
We had to implement a loop to select the item we wanted on the drop down list.

This is the code that ended up working (for 'Website2' mentioned above - the one with no IDs listed).

Set IE = CreateObject("InternetExplorer.Application")
set WshShell = CreateObject("WScript.Shell")
IE.Navigate "WEBSITE-URL" 'Call WEBSITE URL IE.Visible = True
WScript.Sleep 15000 'Sleep for 15 seconds to allow the web page enough time to fully load



Do While True
IE.Document.getElementsByName("status")(2).Checked = true 'Put a checkmark in the "Transfer Failed" field
IE.Document.getElementsByName("status")(3).Checked = true 'Put a checkmark in the "Failed Subtransmission" field
Dim sel
sel = IE.Document.getElementsByName("timePeriod") 'Loop until "Last 12 hours" selected
sel.Options(3).selected = true
IE.Document.All.Item("search").Click() 'Click "Search" to search based on set criteria
WScript.Sleep 300000 'Sleep for 5 minutes - continue in loop until web page is closed
Loop
 
daillest319 - keep in mind that JarIrwin's solution is specific to the markup of WEBSITE-URL. Therefore, the solution would not work with different conditions.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top