jeudi 29 juin 2017

c# - autofill program, how can i autofill select tag in browser? select box?

I recentely want to make auto-typing, auto-fill exploer browser, using windows program with c#.net programming.

I can autytype in text type but i cannot autotype the 'select tag'.

I searched and i thinki i can use 'setAttribute("value","selectIndexnumber")' but, i didn't work well. Explorer does not perceive the 'onchange' state.

So first, I used IHTMLElement3.FireEvent("onchange",null); to invoke 'onchange'

but it didn't work, too.

and Secondely, I used SendKeys.Send("{TAB}");

but it didn't work, too.

how can i autofill the 'select tag' well with no problem like user changed the select tag?

please help me.. thanks in advance!

below is the code that i wrote.

private void button3_Click(object sender, EventArgs e) {

        SHDocVw.InternetExplorer browser;            

        SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
        string filename;
        MessageBox.Show("shellWindows number is " + shellWindows.Count);
        foreach (SHDocVw.InternetExplorer ie in shellWindows)
        {
            filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
            if ((filename == "iexplore"))
            {
                browser = ie;

                String myDocURL = browser.Document.url;
                MessageBox.Show("this is url" + myDocURL);
                if (myDocURL == "http://ift.tt/2twfu5U")
                {
                    IHTMLDocument3 ihtml3doc = (IHTMLDocument3)browser.Document;
                    IHTMLElement3 ihtml3ele = ihtml3doc.getElementById("jobnoticeSn") as IHTMLElement3;
                    IHTMLElement ihtmlele = ihtml3doc.getElementById("jobnoticeSn");
                    ihtmlele.setAttribute("value", "4");
                    IHTMLSelectElement selEle = ihtml3ele as IHTMLSelectElement;


                    //selEle.selectedIndex=4;


                    SendKeys.Send("{TAB}");
                    ihtml3ele.FireEvent("onchange", null);
                    //SendKeys.Send("{TAB}");
                    ihtml3doc.getElementById("jobnoticeSn").children(4).setAttribute("selected", "true");
                    SendKeys.Send("{TAB}");
                    //ihtml3doc.getElementById("jobnoticeSn").children(4).setAttribute("checked", "true");
                    //ihtml3doc.getElementById("jobnoticeSn").children(4).setAttribute("selectedIndex", "true");


                    //ihtml3doc.getElementById("jobnoticeSn").setAttribute("selected", "selected");

                    //ihtml3doc.getElementById("jobnoticeSn").setAttribute("value", "8130");
                    ihtml3doc.getElementById("name").setAttribute("value", "김준혁");
                    ihtml3doc.getElementById("birthday").setAttribute("value", "1989-11-18");
                    ihtml3doc.getElementById("man").setAttribute("checked", "true");
                    ihtml3doc.getElementById("email").setAttribute("value", "jjunest@gmail.com");
                    ihtml3doc.getElementById("password").setAttribute("value", "emfla248248");


                    //ihtml3doc.getElementById("password").scrollIntoView();


                }                    
            }
        }
    }




Aucun commentaire:

Enregistrer un commentaire