Selenium WebDriver Browser Commands

Browser Commands :

Given are some of the most used browser commands.

1. Opening Browser Command:

We already discussed the command for opening browsers (like chrome, firefox, IE, safari) in previous topic i.e. `Launching Browsers In Selenium`

2. To Maximize browser:

Command
driver.manage().window().maximize();

This command is use for maximizing the browser window. Here manage is the method of webdriver which returns the Options interface, window is the method of options interface which returns the window interface and maximize is the method of window interface.

3. To change the position of browser:

Command
Point p = new Point(x,y);
driver.manage().window().setPosition(p);

To change the position of browser we need to call the setPosition() method of window interface which accept the point argument(object of Point class).

Note - Here, x - Horizontal Distance, y - Vertical Distance. We can take any valve of x and y as we want. (Ex. (200,500) )

4. To change the size of browser:

Command
Dimension d = new Dimension(x,y);
driver.manage().window().setSize(d);

To change the size of browser we need to call the setSize() method of window interface which accept the dimensions type argument(object of Dimension class).

Note - Here, x - Horizontal Distance, y - Vertical Distance. We can take any valve of x and y as we want. (Ex. (200,500) )

5. Get Command :

Command
driver.get("URL");

This method loads a new web page in the existing browser window. It accepts String as parameter and returns void. In above command, instead of "URL" we have to write specific URL that we want to open.

6. Get Current URL command:

Command
driver.getCurrentUrl(); 

This method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value.

7. Get Title command:

Command
driver.getTitle(); 

This method fetches the title of the current web page. It accepts no parameter and returns a String.

8. Get Page Source command:

Command
driver.getPageSource(); 

This method returns the source code of the current web page loaded on the current browser. It accepts nothing as parameter and returns a String value.

9. Close command:

Command
driver.close();

This method terminates the current browser window operating by WebDriver at the current time. If the current window is the only window operating by WebDriver, it terminates the browser as well. This method accepts nothing as parameter and returns void.

10. Quit command:

Command
driver.quit();  

This method terminates all windows operating by WebDriver. It terminates all tabs as well as the browser itself. It accepts nothing as parameter and returns void.

#Selenium_WebDriver_Browser_Commands #Opening_Browser_using_selenium #How_To_Maximize_browser_using_selenium #how_To_change_the_position_of_browser_using_selenium #how_To_change_the_size_of_browser_using_selenium #Get_Command_in_selenium #Get_Current_URL_command #Get_Title_command #Get_Page_Source_command #Close_command_in_selenium #Quit_command_in_selenium

(New page will open, for Comment)

Not yet commented...