Question: **Test Environment - Working on writing tests in Selenium web driver in C#.net. And running them via NUnit.**
The base url - <http://localhost/OnlineTest/login.aspx>
Inside of this there is an iframe, inside of which there is a grid,
Here is what I want to automate. 

```
• Go to the Grid
• Click on an image. 
• It opens new window(like a pop up). 
• Go to that window .
• Verify its text & click Close button.

```

I am not able to find a way to go to another window via code.

This is what I have tried - 
IWebElement element=  
driver.SwitchTo().Window("ViewQuestionPreview.aspx?QsnId=Qsn16").FindElement(By.Id("btnClose"));

I have also changed the URL to different combinitions like 

* "/ViewQuestionPreview.aspx?QsnId=Qsn16"
* "http://localhost/OnlineTest/ViewQuestionPreview.aspx?QsnId=Qsn16"
* "/OnlineTest/ViewQuestionPreview.aspx?QsnId=Qsn16"
* "OnlineTest/ViewQuestionPreview.aspx?QsnId=Qsn16"

***Error - No such Window found. NoSuchWindowException***

would appreciate of someone can help.

**Tahir**

Answer: 
You're passing a list of anonymous objects to your view: 

```
select new { Email = x.ParentEmail, UserName = y.Username }

```

While the view is expecting `IEnumerable<ETMS.Models.DB.tblParent>`:

```
@model IEnumerable<ETMS.Models.DB.tblParent>

```

You should change your selection to:

```
select y

```

in order for the code to work.

Update
------

Here is how you *could* use a view model pattern. First, create a view model class, so you're not passing an anonymous type to your view. Let's call it `AwesomeEmailViewModel`, and it looks like you need `.Email`, `.Username` and some other properties, so we'll set those up too.

```
public class AwesomeEmailViewModel
{
    public string Email { get; set; }
    public string Username { get; set; }
    public string FirstName{ get; set; }
    public string LastName { get; set; }
    public int Location_ID{ get; set; }
    public DateTime CreateTime { get; set; }
}

```

Now, modify your query by using object initialization to populate an instance of `AwesomeEmailViewModel`

**Note: I am *guessing* which properties belong to which objects (either tblParent or tblParentEmails, so you will need to double-check these**

```
var members = (from x in db.tblParentEmails
               join y in db.tblParents
               on x.Parent_ID equals y.Parent_ID 
               select new AwesomeEmailViewModel()
               { 
                   Email = x.ParentEmail, 
                   UserName = y.Username,
                   FirstName = y.FirstName,
                   LastName = y.LastName,
                   Location_ID = x.Location_ID,
                   CreateTime = y.CreateTime, 
               }).ToList();
               // I don't know if you'll need the `AsEnumerable()` call

return View(members);

```

Finally, your view has to know what type(s) to expect, so let's modify it to expect a list of our newly created AwesomeEmailViewModel instances.

```
@model IEnumerable<ETMS.Models.AwesomeEmailViewModel>

```

Pay close attention, as I guessed at the namespace as well. In any case, this should give you access to the properties you need inside your view. If you need more, you'll need to modify the new view model class we created as well as the query in your controller action.
Your view expects tblParent but you are passing it the joined table.

You need to create a ViewModel, join your tables there and change your view to expect the ViewModel rather than tblParent.

Thre are loads of examples. Here's one: [ASP.NET MVC ViewModel Pattern](https://stackoverflow.com/questions/1361092/asp-net-mvc-viewmodel-pattern)

I hope this helps

Davy