Press "Enter" to skip to content

C# 윈폼에 올린 브라우저에서 웹페이지 로그인 및 자바스크립트 실행시키기

참조 추가 Microsoft Internet Controls(SHDocVw)와 Microsoft.mshtml 를 하고

using System.Runtime.InteropServices;

using SHDocVw;
using mshtml;

한다.

그 후

InternetExplorer ex = new InternetExplorer();      
ex.Visible = true;
Object obj = null;

ex.Navigate("http://space4u.co.kr", ref obj, ref obj, ref obj, ref obj);

위와 같이 익스플로러를 실행시키고 (space4u.co.kr 로 접속)

굳이 익스플로러가 아니더라도.. WebBrowser를 사용하셔도 됩니다.

private void button3_Click(object sender, EventArgs e)
        {
            IHTMLDocument2 hd;
            hd = (IHTMLDocument2)ex.Document;
            IHTMLElementCollection hCollection = (IHTMLElementCollection)hd.all;
            object obj = "input";                    //input 태그 찾으려고
            IHTMLElementCollection he = (IHTMLElementCollection)hCollection.tags(obj);
            foreach (IHTMLElement helem in he)
            {
                if (helem.getAttribute("name", 0) != null)
                {
                    if (helem.getAttribute("name", 0).ToString() == "email")    //소스를 보고 name속성의 값을 적는다, 아이디 항목
                    {
                        helem.setAttribute("value", (Object)"아이디", 0);       //value 속성에 아이디를 대입
                    }
                    if (helem.getAttribute("name", 0).ToString() == "passwd")
                    {
                        helem.setAttribute("value", (Object)"비밀번호", 0);
                    }
                }
            }
        }

function closeAction(){
alert("종료합니다");
}

function closeActionAA(aa){
alert(aa + "호출");
}

이런 식의 자바스크립트가 있다면,
윈폼에서

this.webBrowser1.Document.InvokeScript("closeAction");
this.webBrowser1.Document.InvokeScript("closeActionAA", new object[] { "하하하"});

이런 식으로 호출할 수 있습니다.

따라서,

this.webBrowser1.Document.InvokeScript("load", new object[] { "code123","3","1","1","1"}); 

요렇게 가능하겠습니다. 


출처 : http://ultragostop.tistory.com/84?srchid=BR1http%3A%2F%2Fultragostop.tistory.com%2F84

Be First to Comment

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다