14. 'get( )' - Selenium WebDriver method to open the specified URL page






In order to perform operations on a browser using Selenium WebDriver commands, we've to first create a driver object for WebDriver and assign the FirefoxDriver Class reference to launch a new Firefox Browser session. In order to do this we have to use the following two statements:

WebDriver _driver;  

_driver = new FirefoxDriver( );

The Selenium WebDriver object  _driver  drives the browser using the Selenium WebDriver Class commands.

Follow the below steps to implement the Selenium WebDriver command get( ):

1. Create any Java Project say 'WebDriver-Project1'  in Eclipse IDE  as shown below:



2. Create any  Package say 'package1' under the project as shown below:



3. Configure the Project to work with Selenium WebDriver as explained in Post# 3. After configuring the Project should look like this under 'Package Explorer' in Eclipse IDE (i.e. as shown below):




4. Create a new Class say 'Class1' under 'package1' package as shown below:




5. Create a Selenium WebDriver object _driver  as shown below:





Note - Resolve the error with the WebDriver class as explained in our previous posts.

6. Create a method say 'setUp( )' inside the 'Class1' class as shown below:


7. Specify the newly created 'setUp' method with '@Before' JUnit annotation as shown below:



Note - Resolve the error with @Before annotation as explained in our previous posts.

8.  Assign the object reference of  'FirefoxDriver' predefined Class to the _driver object of Selenium WebDriver Class and also call the 'FirefoxDriver( )' Constructor without parameters while assigning itself as shown below:


Note - Resolve the error with FirefoxDriver Class as explained in our previous posts.

9. Create another method say 'testMethod( )' and specify it with @Test JUnit annotation as shown below:


Note - Resolve the Error with @Test annotation as explained in our previous posts.

11. Inside the @Test specified method, Type _driver object of Selenium 'WebDriver' Class and press dot '.' on your keyboard as shown below:


3. Type 'get' text after the dot to filter the displayed Selenium WebDriver predefined methods and select the 'get( )' method option as shown below:


4. Ensure that the 'get( )' method got added as shown below:


5. Add semicolon to the end of the statement as shown below:


6. Specify the URL to be opened as shown below:


7. Save and Run the Test using JUnit and observe that the URL specified in the above step got opened by the browser as shown below:



This is how the 'get( )' predefined method of Selenium 'WebDriver' Class works.

Watch the Video on - how the 'get( )' commands opens the specified URL:

Click here to watch the Video.

Download this Project:

Click here to download the Project explained in this post and import into Eclipse IDE on your machine.

Please comment below to feedback or ask questions.

manage( ).window( ).maximize( ) -  to maximize the Browser window will be explained in the next post.




Followers

Labels