Question Issue setting value of a textbox in a webbrowser control

b01000100

New member
Joined
Sep 20, 2011
Messages
2
Programming Experience
10+
Hello everyone,

I am having one heck of an issue with a webbrowser control I am using. As part of my job, I am working on creating a tool to automate an older system that we still use. The part that is being automated is web-based, and the group running the automation does not have access to any automation tools like QTP. In order to give them something they can use, the idea was to build an application just for them. In this application, I have everything working perfectly, with the exception of the most important part: the entry of a policy number. The policy number goes into a textbox, and then the user presses a button. A part of the automation sequence involves the use of a timer.

If I manually navigate to the appropriate page and put the .SetAttribute statement in a button action on my form, it works perfectly fine. However, if I put the .SetAttribute statement anywhere that is being controlled by the timer ticking, it does not work.

So, this works:

VB.NET:
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
    Me.wbPrestige.Document.Window.Frames("WORKSPACE").Document.GetElementById("policynumber").SetAttribute("value", "1234567")
End Sub

but this does not:

VB.NET:
Private Sub timerLoad_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerLoad.Tick
    Select Case currentStatus
        Case Status.wait_for_retrieving
            Me.wbPrestige.Document.Window.Frames("WORKSPACE").Document.GetElementById("policynumber").SetAttribute("value", "1234567")
        'other case statements
End Sub

As a note, I do not have the Select statement in the Tick action; I have it in its own little sub. However, since it functions the same way no matter where it is, and to save space, I combined everything here. Also, at the time of the timer firing and setting things into motion to enter the policy number, the page is already fully loaded, so I don't think it is an issue with that, though I could be wrong.

It does not throw an error. The "1234567" above is passed in as a string, and doing a watch on it at run-time does show that the value is actually in there. It just seems like the .SetAttribute is not registering on the textbox. I have tried a few things ranging from "what-if" all the way to "that-is-so-dumb-it-just-might-work." Nothing seems to do the trick. I have tried sleeping everything for a few seconds just to see if there was an issue there. I have tried issuing the .SetAttribute command a few times in a row thinking it just wasn't taking the first time. Since setting .Focus() didn't seem to work for it, I even went so far as using SendKeys to move focus to the textbox on one attempt and API calls for mouse clicks (to click inside of the textbox) on another attempt. As a last crazy attempt, I had the Select statement doing a .PerformClick on btnTest (which works if I navigate to the page manually).

Would any of you have any ideas for me to try on this? I am open to trying anything that might help. If it works every time, I don't even care if it is such an obscure fix that it looks completely crazy in the code.

Thanks for looking at this!
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
If Possible is the page Available "Online" so i could check? it not then i couldn't do this unless their a Page layed out the same with frames ect..
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
ok i'm dumb LOLz, i missinterpreted what you was talking about, the "wbPrestige" works fine its the select case :|, ok back on track now heh!,
the "Select Case Status.Status.wait_for_retrieving" why are you waiting on retriving to call the pice of code? wouldn't it be on document complete? as if im right the GetElementByID would only work when the documents fully downloaded? as it cant setValue or GetValue when page isn't Complete.


I'm Sure :/
 

b01000100

New member
Joined
Sep 20, 2011
Messages
2
Programming Experience
10+
Thanks for the replies!

Well, the wait for retrieving part of it is a hackish way of making sure the page is loaded. Each page being displayed is a frame inside of the page itself. I found that using documentcomplete was not working for me. It would fire several times in a row for each page, even if the page itself was not visible on the screen. It would fire for the last time, but there were times where the page couldn't even be seen. In these cases, nothing would work for the automation. The buttons wouldn't be recognized, the textboxes weren't recognized, and everything seemed to throw an error. In order to get around that, I tried a few different things. In the end, I settled on an odd solution, but it seems to work for everything but this.

My solution was to do bitmap checkpoints of sorts. The timer ticks every second while the process is running. In each tick, it is looking for a status. Once it gets to the proper case statement (based on the status), it will compare an image of the page as it now is with a known, good image of the page. Well, it is a small part of the page really. I have it set to look at only a small rectangle of the page. Anyway, it will compare them, which is surprisingly fast, and then proceed with the designated action if they match.

In this case, it looks for the proper test image of the page. This includes a part of the page that, if it is visible, will signify that the page is fully loaded AND displayed. Once the test image and the known, good image matches, it will do whatever action exists for it, whether it is pressing a button, downloading a file, or changing something else. The only thing failing out of this entire process is the changing of this textbox.

In terms of it waiting for something, it is...but that isn't really causing the issue. When the code makes it to the .SetAttribute statement, the page is fully loaded, and the textbox appears where it should. The application will execute the .SetAttribute, but nothing will change. If I then press the btnTest button, which has the same .SetAttribute statement in it, the text will change as expected. It all seems a bit screwy to me.

I originally even moved the bitmap compares to the documentcomplete section to see if it would work there, but it didn't. I would love to not have to rely on the bitmap comparisons, but I couldn't get it to work with just the documentcomplete.

Unfortunately, the page is not publicly viewable. It is behind a password wall.

Here is the main form with all of the frames:
HTML:
<HTML>
<HEAD>
<TITLE>Prestige Web Application</TITLE>
</HEAD>

<FRAMESET Rows="20, *" >

<FRAME SRC="TOP.htm"NAME=TOP BORDER=0 FRAMEBORDER=0 NORESIZE SCROLL=NO MARGINHEIGHT=0 MARGINWIDTH=0 >
<FRAME SRC="Agent_Info.asp"NAME=WORKSPACE BORDER=0 FRAMEBORDER=0 NORESIZE MARGINHEIGHT=0 MARGINWIDTH=0 >

</FRAMESET>

</HTML>

Here is the frame I am working on. It was written a loooong time ago, so maybe it contains the answer to the problem. The other frame listed is just a top navigation frame that has three links in it, so I am not showing it.
HTML:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<Script >
var itsLoaded;
function onhelp(){
alert( "you have presed the help key.  There is no help for this screen.");
window.event.cancelBubble = true;
event.returnValue=false;

}
function window_onload(){
var polselected=0;
//debugger
if (frmHiddenFields.Submitted.value == "DOS"){
  set_link();
}
if (frmHiddenFields(1).name == "selectPolicy"){
    itsLoaded=true;
 
    polselected=frmHiddenFields.selectPolicy.options.length;
    while (polselected >= 1){
      polselected-- ;
      if (frmHiddenFields.selectPolicy.options(polselected).text.substring(0,7)==frmHiddenFields.policynumber.value){
        frmHiddenFields.selectPolicy.options(polselected).selected=true;
        break;
      }
    
    }
    frmHiddenFields.policynumber.value = frmHiddenFields.selectPolicy.options(polselected).text.substring(0,7);
  
} //end if
// itLoaded indicates that there is at least one policy in the select list
// Submitted=="Success" indicates that a policy has been selected or entered and is OK to submit to the webclass.
if (frmHiddenFields.itsLoaded){
  
  if ((frmHiddenFields.Submitted.value == "Success") || (frmHiddenFields.Submitted.value == "SuccessDOS")){
      if (frmHiddenFields.policynumber.value < 5000000){
          frmHiddenFields.action="/nwpwebclass.ASP";} 
          else
      if (frmHiddenFields.policynumber.value < 4355000){
            if ((frmHiddenFields.usercode.value == "08588") 
                 || (frmHiddenFields.usercode.value == "08600")){
        frmHiddenFields.action="/nwpwebclass.ASP";
           }    
    }
    document.body.style.visibility ="hidden";
    frmHiddenFields.submit();
  }
 }
} // end function onload
function policy_onselect(){
frmHiddenFields.policynumber.value = frmHiddenFields.selectPolicy.options(frmHiddenFields.selectPolicy.selectedIndex).text.substring(0,7);
itsLoaded=true;
//set_link();
}

function set_link1(){
dnld.style.visibility ="visible";
dnldLink.href='http:'+ lName + '/ildata/0' + frmHiddenFields.policynumber.value + '.flt';
dnldLink.innerText = '0' + frmHiddenFields.policynumber.value + '.flt';

}

function set_link(){
var iTop = new Number(0);
var iLeft = new Number(0);
var sOptions=new String("");
var fname;
var result;
iTop = Math.floor((window.screen.availHeight - 200)/2);
iLeft = Math.floor((window.screen.availWidth - 350)/2);
fname='dnld.asp?policynumber=' + frmHiddenFields.policynumber.value +'&dosflag=' + frmHiddenFields.Submitted.value;
sOptions = "resizable=0,toolbar=0,top=" + iTop.toString() +",left= " + iLeft.toString()+ ",width=350,height=200";
frmHiddenFields.Submitted.value=''; 
result=open(fname,frmHiddenFields.policynumber.value,sOptions);
}

function number_change(){
itsLoaded=false;
//}
}

function form_onsubmit(){

dnld.style.visibility ="hidden";
//document.body.style.visibility ="hidden";
//if ((frmHiddenFields.policynumber.value < 5000000) ){
//    frmHiddenFields.action="/nwpwebclass.ASP";
//    }
    if (frmHiddenFields.policynumber.value < 5000000){
          frmHiddenFields.action="/nwpwebclass.ASP";} 
  else
      if (frmHiddenFields.policynumber.value < 4355000){
        if ((frmHiddenFields.usercode.value == "08588") 
             || (frmHiddenFields.usercode.value == "08600")){
        frmHiddenFields.action="/nwpwebclass.ASP";
           }
        }
frmHiddenFields.Submitted.value = "SubmittedI";
frmHiddenFields.style.visibility ="hidden";
// check if there is a select list
if (frmHiddenFields(1).id=="selectPolicy"){
   if (frmHiddenFields.updateChk.checked==true){
      itsLoaded=false;
      frmHiddenFields.updateChk.checked=false;
    }
}

if (!itsLoaded){
// if manual submit we want to return to this asp for further evaluation
//asp will load data from mainframe - set itsLoaded if valid policy
  frmHiddenFields.action="inforce.asp";
}

} // end function onsubmit


</SCRIPT>
<BODY style="FONT-WEIGHT: normal; FONT-SIZE: 12pt;  LINE-HEIGHT: normal; FONT-STYLE: normal; FONT-VARIANT: normal" bgcolor=#fafad2 onload="window_onload();" onhelp="onhelp();" text="#000000">

<form method="post" name="frmHiddenFields" action="webclass1.ASP" onsubmit="form_onsubmit();" >

<P style="FONT-WEIGHT: bold; FONT-SIZE: larger; MARGIN-LEFT: 15px">
<BR>Retrieving Inforce Policy Values
</P>
<DIV style="font-family:Arial ;Font size:10pt; MARGIN-LEFT: 50px; MARGIN-RIGHT: 150px">Prestige requires current policy values as a starting point in order to project future policy values.  
  You enter a policy number and then press the Continue button to import these values into the system to run an illustration.  
  The policy value record is then saved for 30 days and available for you to retrieve if additional scenarios are required.
  </DIV><BR>
<DIV style="MARGIN-LEFT: 100px"><FONT face=Fixedsys>
Enter Policy Number: 
<INPUT ID=policynumber name=policynumber Title="Enter policy number to download"  value="" onchange="number_change();" style="WIDTH: 60px; POSITION: absolute; HEIGHT: 20px; BACKGROUND-COLOR: #f0f8ff">

<P style="MARGIN-LEFT: 100px">
Or</P><P>Select inforce policy:<select id=selectPolicy style='WIDTH: 150px; HEIGHT: 24px;position:absolute; BACKGROUND-COLOR: #f0f8ff' size=1 name=selectPolicy onchange='policy_onselect();' onmousedown='policy_onselect();' ><option '1234567'>1234567,9/19/2011 </option></select> <INPUT ID=updateChk type=checkbox  style='MARGIN-LEFT: 160px; WIDTH: 22px; POSITION: relative;WIDTH: 22px;Height=22px; BACKGROUND-COLOR: #f0f8ff' size=1><i>Current policy values  </i>
</P>
</DIV>
<P align=center><INPUT id=submit1 style="BORDER-RIGHT: outset; BORDER-TOP: outset; BORDER-LEFT: outset; BORDER-BOTTOM: outset" accesskey="3" type=submit value=Continue name=submit1 ></P>
<P id=pdnld style='MARGIN-TOP: 50px;MARGIN-LEFT: 50px'>To illustrate this policy locally instead of on the web, click here to <INPUT id=btndownload style='WIDTH: 150px; HEIGHT: 22px' type=button size=99 value='Create download link' name=btndownload onclick='set_link();'></P>

<INPUT id=select2 name=Special value="" type=hidden >  <INPUT id=usercode name=usercode type=hidden value="74042" >
<INPUT id=fecode name=fecode type=hidden value="AAAAA">  
<INPUT id=agentstreet1 name=agentstreet1 type=hidden value="" ><INPUT id=agentStreet2 name=agentstreet2 type=hidden value="" ><INPUT id=agentcity name=agentcity type=hidden value="" > 
<INPUT id=agentstate name=agentstate type=hidden value="AK" ><INPUT id=agentzip name=agentzip type=hidden value="" >
<INPUT id=agentlicnum name=agentlicnum type=hidden value="" ><INPUT id=producercode name=producercode type=hidden value="74042" ><INPUT id=SessOK name=SessOK type=hidden value="" > 
<INPUT id=placa name=placa type=hidden value="0"><INPUT id=BusinessType name=BusinessType type=hidden value="Inforce Illustration"><INPUT id=producttype name=producttype type=hidden value="Variable Life Insurance"><INPUT id=product name=product type=hidden value=""><INPUT id=AgentName name=AgentName type=hidden value=" ">
<INPUT id=SessOK name=SessOK type=hidden value="" ><INPUT id=Submitted type=hidden name=Submitted value="Submitted"><INPUT id=itsLoaded type=hidden name=itsLoaded value="False" >
<INPUT id=AgentNameF name=AgentNameF type=hidden Value="" ><INPUT id=AgentNameL name=AgentNameL type=hidden Value="" >

</form></FONT>
</BODY>
</HTML>

I doubt those were overly helpful, but I figured I would give it a shot. I figure I will be out of luck with this situation. As is often the case with some of our systems, they don't seem to function the way they should or the way you expect them to.

I really appreciate the help. If you know of better ways for me to do any of this, I would be open to suggestions. This is kind of a throw-together project, so I am not exactly saying I am doing the right thing all of the time with it.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,609
Location
Norway
Programming Experience
10+
I just tested with your page documents and called SetAttribute code from DocumentCompleted event handler like this:
If e.Url.ToString.EndsWith("Agent_Info.asp") Then
    ' ....SetAttribute("value", "1234567")
End If

This loaded the policynumber element with that value.
 
Top Bottom