Selenium WebDriver
Browser Commands
The
very first thing you like to do with Selenium is to opening and closing a new
browser. Below are the numbers of commands you can apply on the Selenium opened
browser.
1. Get
Command
Purpose: This command is use to open a new
web page in the current browser.
Command: driver.get(URL);
Parameters: url – The URL to load. It is best to use a
fully qualified URL
driver.get("wwww.google.com");
2. Get Title
Command
Purpose: This command is use to get the title
of the current page.
driver.getTitle();
3. Get Current URL
Command
Purpose: This command is use to get the URL
of the page currently loaded in the browser.
driver.getCurrentUrl()
4. Get Page
Source Command
Purpose: This command is use to get the source
of the last loaded page.
driver.getPageSource();
5. Close Command
Purpose: This command is use to close the
current window of the browser, if it’s the last window it will close the
browser.
driver.close();
6. Quit Command
Purpose: This command is use to quit the
browser and all the opened windows in the browser.
driver.quit();
Selenium WebDriver
Browser Navigation Commands
The
navigate interface exposes the ability to move backwards and forwards in your
browser’s history but navigate().to() and get() do exactly the same thing.
One’s just a lot easier to type than the other.
To Command
Purpose : This command is use to navigate on
specific page or URL in between the test Command :
driver.navigate().to(URL); Parameters : url – The URL to load. It
is best to use a fully qualified URL
driver.navigate().to("http://www.gooogle.com");
Forward
Command
Purpose : This command is use to go on to next
page like browser’s forward button.
driver.navigate().forward();
Back Command
Purpose : This command is use to go back to
previous page like browser’s back button.
driver.navigate().back();
Refresh Command
Purpose : This command is use to refresh the
current page.
driver.navigate().refresh();
Selenium
WebDriver Switch Window Commands
Some web
applications have many frames or multiple windows. Selenium WebDriver assigns
an alphanumeric id to each window as soon as the WebDriver object is
instantiated. This unique alphanumeric id is called window handle.
Selenium uses this unique id to switch control among several windows. In simple
terms, each unique window has a unique ID, so that Selenium can differentiate
when it is switching controls from one window to the other.
GetWindowHandle
Command
Purpose: To get the window handle
of the current window.
String handle= driver.getWindowHandle();//Return a
string of alphanumeric window handle
GetWindowHandles
Command
Purpose: To get the window handle
of all
the current windows.
Set<String>
handle= driver.getWindowHandles();//Return a set of window handle
SwitchTo
Window Command
Purpose: WebDriver supports moving
between named windows using the “switchTo” method.
driver.switchTo().window("windowName");
Or
Alternatively,
you can pass a “window handle” to the “switchTo().window()” method.
Knowing this, it’s possible to iterate over every open window like so:
for
(String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle);}
SwitchTo
Frame Command
Purpose: WebDriver supports
moving between named frames using the “switchTo”
method.
driver.switchTo().frame("frameName");
SwitchTo PopUp Command
Purpose: WebDriver supports
moving between named PopUps using the “switchTo”
method. After you’ve triggered an action that opens a popup, you can access the
alert and it will return the
currently open alert object. With this object you can now accept, dismiss, read its
contents or even type into a prompt. This interface works equally well on
alerts, confirms, and prompts.
driver.switchTo().alert();
No comments:
Post a Comment