简体   繁体   中英

Automating Website/Web forms using C# in Firefox, using Visual Studio 2010?

If anyone can help me I'd appreciate it.

I'm working on a C# file in Visual Studio 2010 that I need to be able to test a website with multiple form pages, for the purpose of an example we'll refer to them all as 1.aspx, 2.aspx etc.

I've my code that fills out the first page (1.aspx) fine, and click the "continue" button to load the next page, but when it gets to 2.aspx it won't continue to fill out the form.

We'll say an element on the 2.aspx page is called "DOB". On trying to run from the start (I've all the pages form data in the one .cs file) I get an error like "DOB does not exist in the current context".

Anyone's insight into this would be really appreciated!

In all honesty, it sounds like you might be better off using the WatiN Framework . I have been writing automation with it for years and the way that it is implemented and its ease-of-use make it worth the slight learning curve.

Just to add a bit more to the answer; and yes, this is pseudo-code:

[Test]
public void Should_attach_to_browser()
{
     ExecuteTest(browser =>
     {
          browser.GoTo(NewWindowUri);
          browser.Link(Find.First()).Click();

          var findBy = Find.ByTitle("New window");
          var newWindow = Browswer.AttachTo(browser.GetType(), findBy);
          newWindow.Close();
     });          
}

In the code above, note the Browser.AttachTo(browser.GetType(), findBy); method. Based on what I have understood of your question, the .AttachTo() method would work well since you would be able to take the focus off the current form and assign it to the next in your work/execution flow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM