So I've been doing some research for a while and I'm at a dead end. I'm doing some IE automation. In C#/.NET, how do I probe for and consume a javascript alert() or confirm() so I can do things like grab its text and click the OK\Cancel buttons?
Update:
I need to reiterate: I need to be able to pull and verify the text from an alert() or confirm() as well as send it an OK or Cancel click. An example of such a test would be to make sure that, when I click on delete, the confirm() doesn't say "Are you sure you'd like to go to Mexico?" or anything else except the proper message.
Just in case, let me reiterate: For the purposes of this test, I have zero control over the source of the website in question.
Lastly, I'm using SHDocVw.InternetExplorer
.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".
I think you're going to have to use FindWindow, SendMessage, etc. This is how WatiN does its dialog handling.
I think what you are looking for is the IDocHostshowUI COM interface. If I read the documentation correctly and my assumptions are correct ShowMessage function will be called when an alert() or confirm() is called in JavaScript.
I've not done this myself so I am only guessing. Here are some examples of someone showing an example of using that interface (and many others) in C#. WebBrowserSample2 sounds like what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With