To create a instance of a browser,
WebDriver driver=new InternetExplorerDriver();
WebDriver driver=new FireFoxDriver();
WebDriver driver=new ChromeDriver();
You must have the driver file(which can be downloaded from the selenium site) in your local system for these commands to work. The files can be added in a place where your program can access them or you need to set their path in your program using commands like
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");System.setProperty("webdriver.ie.driver", "/path/to/iedriver");
Firefox driver comes with the selenium server jar so we don't have to download it separately.
(or)
The following code can be used to execute scripts in the remote machine. The remote machine should have a selenium server instance running.
DesiredCapabilities capability=new DesiredCapabilities();
capability.setBrowserName("internet explorer");
//The name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}WebDriver driver=new RemoteWebDriver(new URL("url of remote machine"),capability);
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
Get Title Command
Purpose:
This command is use to get the title of the current page.
Driver.getTitle();
Get Current URL Command
Purpose:
This command is use to get the URL of the page currently loaded in the
browser.
driver.getCurrentUrl()
Get Page Source Command
Purpose: This command is use to get
the source of the last loaded page.
driver.getPageSource()
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()
Quit Command
Purpose:
This command is use to quit the browser and all the opened windows
in the browser.
driver.quit()
Refresh Command
Purpose: This command is use to refresh the current browser.
driver.navigate().refresh();
Back Command
Purpose: This command is use to navigate
back in the
current browser.
driver.navigate().back ();
Forward Command
Purpose: This command is use to navigate
forward in the
current browser.
driver.navigate().forward ();
To Command
Purpose: This command is use to a
page in the
current browser.
driver.navigate().to (URL);
Aren't you wondering what's the difference between get(URL) and navigate().to(URL) commands?
The end result for both the commands is the same as in the page is loaded when the command is executed. The difference is the URL is stored in the navigation history when you use navigate().to() so you can use navigate().back() and navigate().forward() to go back and forth but when you use get() you don't have that option.
Comments
Post a Comment