Webdriver

Uploading a file with sendKeys method

The Easy way of uploading a file is simple case of just finding the element and typing the absolute path of the document into it.

It is mandatory that it works only when the textbox is enabled. So please make sure that the input element is visible. In the below example 'uploadsubmit' is the name of that element and in 'sendKeys()' we have to specify the absolute path of the content that we want to upload (that can be file/image/video etc).

Sample HTML Code should look similar to this :

Upload file using AutoIT

With the help of AutoIt tool (open source tool) we can upload by transferring the control from Selenium webdriver to AutoIt.

We need to explicitly call the AutoIt script from our program.

About AutoIT : AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

We need to call the AutoIt script after clicking on the upload button. Immediately after clicking on Upload button, the control should be transferred to AutoIt by the below statement which takes care of uploading the file.

Webdriver Select with Multiple Attribute

WebDriver’s support classes called “Select”, which provides useful methods for interacting with select options. User can perform operations on a select dropdown and also de-select operation using the below methods.

User can also get the text of the values in the dropdown. Also can get the option which are selected by the user. To use these options, the Select Tag should have "multiple" attribute.

Webdriver SELECT Methods to work with Dropdowns

WebDriver’s support classes called “Select”, which provides useful methods for interacting with select options. User can perform operations on a select dropdown and also de-select operation using the below methods.

Method Name: selectByIndex 

Syntax: select.selectByIndex(Index);
Purpose:  To Select the option based on the index given by the user.
There is an attribute called "values" which will have the index values.

The below is the sample html code using index
Example
HTML Code

How to addcookie with Selenium Webdriver

Using webdriver we can easily pass the cookie to the domain. In order to pass cookie, we should use a method named "addCookie(cookie)"

Method Name: addCookie(Cookie cookie)
Syntax:driver.manage().addCookie(arg0);
Purpose: To add a specific cookie into cookies. If the cookie's domain name is left blank, it is assumed that the cookie is meant for the domain of the current document.
Parameters: cookie - The name and value of the cookie to be add.

Example:

Navigation Methods in Webdriver with Examples

Navigate.To(URL)

Method Name: navigate.to(URL)
Syntax: driver.navigate().to(URL);
Purpose: This methods Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete.
Parameters: URL – It should be a fully qualified URL.

Example:

Defining Firefox Profile preferences using Selenium Webdriver

Some times, you may need to update the preferences within Firefox. We can do this by instantiating a Firefox Profile object and then update the settings.

We will then need to pass this object into FirefoxDriver which will load the profile with your defined settings.

You can check them using command "about:config" in the borwser. It will display a warning message and then asks you to proceed if required. Becarefull when doing any changes.