1

I'm having an issue where the team that developed a web based application used a WYSIWYG editor and, a couple months ago, they updated some of the HTML form labels and IDs. My team creates macros that work with the DOM to gather/enter/update information in these web based applications. When I got a report about the update, I looked into it and found that the original code for a specific line was:

strQ = objIE.document.getElementById("ctl00_ContentPlaceHolder1_lblQueue").innerTEXT

Whatever is in the label for this element ID would be stored in strQ and used to detect the work queue the user is working from in another web based application. When the team for the first application made the update, the code for the label's element ID became:

strQ = objIE.document.getElementById("ContentPlaceHolder1_lblQueue").innerTEXT

As you can see, they removed the ctl00_ from the beginning of the label' element ID. Just a few days ago, then made another update and it was added back. Since all the label IDs begin with ContentPlaceHolder1_ and can sometimes contain ctl00_, is there any way of using RegExp to simply find lblQueue in the label's ID?

Lou
  • 389
  • 3
  • 20
  • 38
  • You might want to have a look at [this](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – wazz Sep 16 '19 at 17:52
  • Also: https://weblog.west-wind.com/posts/2009/nov/07/clientidmode-in-aspnet-40 – wazz Sep 16 '19 at 17:57
  • @wazz So, if I understand you offering both links, I can't use RegExp to locate the label's ID, but I can somehow use ClientIDMode to find it? – Lou Sep 16 '19 at 18:36
  • Read the 2nd article. It's a way of adding a setting that permanently gets rid of extra crap in the markup, like `ctl00`. Maybe the developers can include it. – wazz Sep 16 '19 at 19:44
  • you might still be able to use regex, not sure. check back for other answers. – wazz Sep 16 '19 at 19:45
  • I'm meeting with the developers today, so I may be posting a solution, but I'm trying to get ahead of them on this. They are the ones that suggested using RegEx and offered this as a solution (which I haven't got working): `strQ = objIE.document.getElementById(“\wContentPlaceHolder1_lblQueue”).innerTEXT`. – Lou Sep 17 '19 at 12:54

1 Answers1

2

You can use the querySelector as described here: https://stackoverflow.com/a/24296220/4181058

In your example it would be (id$ means where the ID 'ends with'):

document.querySelector('[id$="lblQueue"]').innerText
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
  • I've seen examples like this, but they were outdated and I didn't see the one you sent me. Thanks. Now that I understand what they are doing, I'll give this a try and see if it works for me. – Lou Sep 17 '19 at 12:56
  • I just updated my code with your suggestion and it worked perfectly! Thanks. – Lou Sep 17 '19 at 13:40
  • It can be used either way. I used it in VBScript: `objIE.Document.getElementById("[id$='txtClaimID']").Value = strICN`. – Lou Sep 17 '19 at 20:26