What are Browser Commands?
Selenium WebDriver provides predefined methods and functions that enable developers to interact directly with browsers.
These commands provide exact control over the browser's actions, like loading specific pages, extracting details such as page titles and URLs, accessing page source code, and controlling browser windows.
1. get(String url) command
get(String arg0):
return type: Nothing
parameter: Stringcalling driver.get() multiple times does not open a new window; it simply reloads the same page in the current browser tab.
Wait until page load completes
driver.get()
↓
Browser starts loading page
↓
Wait until page load completes (basic level)
↓
Next line of code executes
//***get(String url) command*********
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserCommands {
public static void main(String[] args) {
WebDriver driver=new ChromeDriver();
driver.get("https://eduplaynation.2-min.in/");
String URL = "https://eduplaynation.2-min.in/";
driver.get(URL);
}
}
2.Get CurrentUrl Command
getCurrentUrl() retrieves the web address (URL) of the page currently displayed by the browser.
return type: String
parameter: Nothing
It is mainly used to:
Verify page navigation
Check redirects
Validate whether expected page opened
Debug test execution
public class BrowserCommands {
public static void main(String[] args) {
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
System.out.println(driver.getCurrentUrl());
}
}
3.Get Title Command
getTitle();
This method fetches the Title of the current page.
Return type:String
Parameter: Nothing.

4.Get page Source Command:
getPageSource() is a method in Selenium WebDriver that returns the complete HTML source code of the currently loaded webpage as a String.
Return type:String
Parameter: Nothing.

5.Quit command
Return Type:Nothing
Parameter: Nothing
This command will only close the browser's window opened by the selenium in the same session. If any browser is opened manually, this will have no impact on the same. Also, there is no impact on the browsers opened in another run or session even by the Selenium.

6.Close command:
This method Close only the current window the WebDriver is currently controlling.
Return Type:Nothing
Parameter: Nothing


Top comments (0)