开发者

open and manipulate a web form in firefox

开发者 https://www.devze.com 2023-02-17 13:36 出处:网络
I need to open a link from a winform application in a firefox browser. Then I would like to autocomplete the form\'s inputs (like username and password) and generate a button click (a login button to

I need to open a link from a winform application in a firefox browser. Then I would like to autocomplete the form's inputs (like username and password) and generate a button click (a login button to submit the form for instance).

I'm currently doing the same think with IE using Interop.SHDocVw.dll, but I need a firefox implementation. Is there such a dll for the mozilla's broswer? Do I need to develop a plugin? or开发者_如何学C maybe I might have to use a UI testing framework?

thanks for the answers!

Bruno


So I start Firefox using Process start:

Process.Start("firefox.exe", "http://www.mywebsite.com");

I then use USER32.DLL to find and focus on the Firefox window:

// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

private void btnEnterText_Click(object sender, EventArgs e)
    {
        var handle = FindWindow("MozillaUIWindowClass", "Environnement de recette 1.4.0.3 - Mozilla Firefox");
        SetForegroundWindow(handle);
        SendKeys.SendWait(txtEntry.Text);
    }

I found the window's class and title thanks to spy++.

So my problem no is to move to the next input on the page... when I use this:

SendKeys.SendWait("{TAB}");

it moves the focus as is I pressed TAB 2 times.... Does anyone knows what's happening ?

0

精彩评论

暂无评论...
验证码 换一张
取 消