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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebBrowser Problem with Java Alert();

Status
Not open for further replies.

davem99

Programmer
May 19, 2003
74
US
I have a Web Browser control on a form that programatically interacts with a website.

On this website there's a function that performs a search and the java code in this very complex page throws an Alert telling me how many items were found.

My problem is that this Alert stops my App from running until I hit OK.

Any ideas how to work around this?!??!

Thanks folks and Happy New Year!
 
What kind of alert is thrown? Depending on the alert you need to take the alert and then find a way to recognize it in vb... Once you can recognize the alert you need to perform an action (the button click).

Step 1: let’s say its some sort of a pop up window alert? Maybe you could use findwindow function? or
look at the html code using the inet or webbrowser control to check to see if the alert is up?

Step 2: Pressing the button... I’m not sure the best way to go about this... I would suggest somehow bypassing the button if possible? Depending on how it is called I would need more specifics to determine this...
 
Hi chtrips,

My problem is that I'm automating a fairly mundane task on a 3rd party site.

My app contains a browser control and my application fills in criteria then hits a 'Search' button. When this happens, an Alert appears with 'Your search returned 99 rows. Hit OK to view them or hit cancel to search again.'

It's a regular java alert but I can't poke around within my app because as soon as it appears my code stops until after the alert is OK'd or Cancel'd.

I'd thought about maybe having another app that hunts for the window and messages (or even SendKeys) to the browser but that seems like hard work!!!

Any help, much appreciated!

dave
 
Is this Alert(); from a java applet or javascript?

If it is from script you can have your vb code modify/remove the Alert from the page before it gets hit.
 
Thanks SemperFi!

I believe it's a script since the page show none of the typical behavior of an applet loading.

I see this code in the source:

<SCRIPT language=&quot;javascript&quot; src=&quot;/Include/ErrorsJS.asp&quot;></SCRIPT>
<SCRIPT defer language=&quot;javascript&quot; src=&quot;/Include/ParamJS.asp&quot;></SCRIPT>

How do I go about changing the script through VB? I will be indebted to you for eternity if this works!!!!!

Thanks,

dave
 
Ok your going to task me here.....I'll blurt out the basic concept and see if I can get it actually working.

With the internet control you get a .Document property. This property gives you access to the actual web page.

The following code should give you a string with the actual source

Code:
    Dim t
    Dim sSource as String
    For Each t In WebBrowser1.Document.All
        sSource = sSource & vbNewLine & t.outerhtml
    Next


You can play with the elements and find the one that has your offending Alert(); statement and the easiest thing to do is comment it out.

Problem here is that the .Document property is read only.....

This is going to be tricky. You might be able to make a web page that you store locally that has script to change the 3rd party web page...but I'm not sure how you could do this directly.

Maybe something like a local webpage like this

Code:
<HTML>
<HEAD>
<META name=&quot;VI60_DefaultClientScript&quot; Content=&quot;VBScript&quot;>

<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub ifDoc_onactivate
	dim t
	dim sHold 
	sHold = ifDoc.document.all(&quot;IDGOESHERE&quot;).innerHTML
	sHold = REPLACE(sHold,&quot;Alert(&quot;,&quot;//Alert(&quot;)
	ifDoc.document.all(&quot;tdUserIDLbl&quot;).innerHTML = sHold

End Sub

-->
</SCRIPT>
</HEAD>
<BODY>
<IFRAME ID=ifDoc FRAMEBORDER=0 SCROLLING=NO SRC=&quot;[URL unfurl="true"]http://URLGOESHERE&quot;></IFRAME>[/URL]
</BODY>
</HTML>



Problem is that the more I look at it the more difficult it gets. I don't think you can modify a tag if it doesn't have an ID or NAME.

But this is a starting point....maybe someone over in one of the web forums might have a better idea.
 
Hmm... Here’s a trick that might work... I’ve used it but I’m not very familiar with scripting or your situation.

1. Download the pages Scripting
2. Search for the script that causes the popup message
3. Remove said script via replace
4. Save the script to your hard drive as a webpage
5. open the page in your webbrowser control
6. the alert should be bypassed


Note: by saving it to your hard drive there may be other changes that you have to make to the script before viewing, for it to work properly. (because the path has changed)
If you are familiar with html and java it should be fairly simple but then again that’s easy for me to say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top