Saturday, 15 March 2014

How to maximize the browser window with selenium webdriver in C#.Net?

We can maximize the browser window launched by Selenium Webdriver using below line of code.

 driver.Manage().Window.Maximize();

The complete example in C#.Net is given below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;
namespace Abc
{
    class Program
    {
static void Main(string[] args)
 {

//IWebDriver x = new InternetExplorerDriver(@"F:\selenium\csharp");
//IWebDriver x = new FirefoxDriver();
 IWebDriver driver=null;
            try
            {
                driver = new ChromeDriver(@"F:\selenium\csharp");
                driver.Url = "http://www.google.co.in";
                //maximize the browser window
                driver.Manage().Window.Maximize();
                driver.Navigate();
              }
            catch(Exception e){
                Console.WriteLine("Exception ....*********"+e.ToString());            
            }
           
            finally{
            Thread.Sleep(2000);
            driver.Quit();
            Console.ReadLine();
            }          
        }
    }
}



What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

3 comments:

  1. Awesome work Sir...Thank you very much

    ReplyDelete
  2. nice. worked like magic. thanks dude

    ReplyDelete

Buy Best Selenium Books

About Me

My photo

Self-motivated software professional