December 2, 2021

Selenium Interview Questions on Textbox Part -2

December 02, 2021 18
Selenium Interview Questions on Textbox

1. How to get text in textbox?
2. How to get attributes like size, placeholder of text box?
We have to use getAttribute command to get attrubte values of textbox.
driver.findElement(locator).getAttribute("value"); -- for text in textbox 
driver.findElement(locator).getAttribute("attributeName"); -- For any attribute





December 1, 2021

Selenium Interview Questions on Textbox Part -1

December 01, 2021 1
Selenium Interview Questions on Textbox

1. How to type into a text box using selenium webdriver?

We have different ways to type text into textbox/textfield or text area

1. Using sendkeys - driver.findElement(locator).sendKeys("text");
2. Using JavascriptExecutor document.getElementById
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById('id').setAttribute('value','text')");
3. Using JavascriptExecutor arguments[0].value
jse.executeScript("arguments[0].value='enter the value here';", WebElement);



January 11, 2020

Execute scripts on Edge Browser

January 11, 2020 2
In this post we will see how to execute webdriver scripts in EDGE Browser.

For other browsers like google chrome and firefox we need to download corresponding exe files and need to set system path.

If you are using latest version of edge i.e 18+ then the set up is little bit different.

Check Edge Version : 
Launch edge browser
Right hand top corner you see 3 dots.
Click on 3 dots and click on Settings
At the end you can see browser information. Mine is Microsift Edge HTML 18.1863

Download exe file:
Edge browser exe files are available in below path
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads

If your edge version is less than 18 then straight away download corresponding exe file and in your webdriver script need to set the system property like below.


If your edge version is 18 then need to perform belwo steps.

Below command should be executed in an elevated command prompt.

DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0

Elevated command prompt is nothing but need to launch your command prompt as admin.

Once you execute the command it will download MicrosoftWebDriver.exe file under C:\Windows\System32 folder.

Thats it...you can execute your scripts in Edge browser. no need to set up any path.

Below is the sample code:






Video is available here:


October 2, 2018

Automatic download and management of Selenium WebDriver binaries (Driver.exe files)

October 02, 2018 9
In this post we will see how to avoid downloading driver.exe file and setpath for browser binary.

As you guys already know in order to use chrome, firefox or edge browsers, first we need to download a binary file (driver.exe) and need to set path which allows Webdriver to handle browsers.



Below is example how to set path:


By adding a small dependency in your POM.xml (Assuming you are using maven project) we can avoid downloading binary files and set path. In addition, we have to check manually when new versions of the binaries are released. WebDriverManager will do this job for us automatically


How it works:

WebDriver Manager actually gets your browser version and download the compatible browser binary by itself to make you run your code without interruption.

So now, rather than setting the browser binaries, you just need to add below line of code and you’re done


The line WebDriverManager.chromedriver().setup(); WebDriverManager does magic for you:

  1. It checks for the latest version of the WebDriver binary.
  2. It downloads the WebDriver binary if it’s not present on your system.
  3. It exports the required WebDriver Java environment variables needed by Selenium
By default downloaded binary files (driver.exe) files will be stored in .m2 folder. By using below commands you can get the downloaded version and path of binary file.


Below is sample code:



Video is available here:


January 18, 2017

Git Installation

January 18, 2017 51
Git :

Git is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for software development,but it can be used to keep track of changes in any files. As a distributed revision control system it is aimed at speed,data integrity and support for distributed, non-linear workflows

Steps to Install Git:

Download Latest Git installer  Git For Windows.

While installing Git make sure you check 2 check boxes. GIT Bash and GIT GUI.


When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation.

While installing keep default options that will be ok for most of the users.


Once the installation is done if you search for git you will see Git Bash and GitGUI.

GitBash:

Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.



GitGUI:

Git for Windows also provides the Git GUI, a powerful alternative to Git BASH, offering a graphical version of just about every Git command line function, as well as comprehensive visual diff tools.


Shell Integration:

Simply right-click on a folder in Windows Explorer to access the BASH or GUI.



Next Post on Create Repository and Clone it to Local Machine.

Create Repo Using GitHub


Git and GitHub

January 18, 2017 9
Git and GitHub
In this article I will discuss about Git and GitHub.

First question comes in everybody's mind, what is Git and what is GitHub. Both are same or different?


GIT:
Below is the definition from GIT official site.
 (https://git-scm.com/)
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency

Git is a distributed version control system.

There are two types of  version control systems out there. “centralized” and “distributed”.

Centralized:
A single place everyone can check in and check out.  Example :CVS, Subversion, and Perforce

Distributed:
Every developer/user has their own repo. Everyone can push changes into a common repo. Example : Git, Mercurial, Bazaar or Darcs


The below diagram show the core difference.

SVN & Git - Git Actions





To know more or practice git commands please see this link https://try.github.io/levels/1/challenges/1


GitHub:

Online project hosting using Git. It Includes source-code browser, in-line editing, wikis and ticketing. Free for public open-source code.

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.

GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.


Below are some of the advantages of GitHub:


  • Version control your projects
  • Push your projects to GitHub and let the world know how nice and useful code you write
  • Explore other’s projects on GitHub, get inspired code more, or contribute to their project
  • Collaborate with others, by letting other people contribute to your projects or you contributing to other’s projects

Below are some posts related to Git and Github.

Git Installation

Create Repo Using GitHub

How to use Git commands



July 12, 2016

Perfect Example for Handling Window,popup,Frame and Alerts

July 12, 2016 8
Perfect Example for Handling Window,popup,Frame and Alerts
In this post i will explain about how to handle

  1. Multiple windows
  2. Popups
  3. Tabs
  4. Frames
  5. Alerts
and how to write customized functions, instead of duplicating the webdriver code.

Here is one example to switchToChildWindow()
This method is useful to switch to new window/tab/popup if you have only 2 windows/tabs/popup then you can use below customized function.



In the below example i wrote different functions 

  1.  isElepresent(By locator) -- Verify if the element is present or not
  2. selectByText(By locator, String visibleText) select a value from dropdown
  3. switchToChildWindow() ---Switch to  child window. If there are only two windows.
  4. switchToWindowByTitle(String title)  ---Switch to child window. Use this if title of the pages are unique.
  5. switchToFrame(WebElement locator)  --switch to frame by locating the frame.


Scenario: which has all multiple windows/tabs/popups/alerts/frames etc...

  1. Open http://www.hdfcbank.com/
  2. Close the Ad window if that is visible
  3. Click on Agri Link --which will open new window/tab
  4. Select "Telugu" from dropdown
  5. Handle the alert
  6. Select "English" from dropdown
  7. Click on Account Details --which will open new window/tab
  8. In the new window, enter customer ID --"test" (Actually this text box is in frame)
  9. Click on Privacy Policy link (Actually this link is in another frame) --which opens new window/tab/popup
  10. Click on CSR link on Privacy Policy page.
  11. Now come back to Main window (Parent window) 
  12. Click on Customer Care.

Below is the code:







June 13, 2016

Handling OnChange events using Selenium webdriver and Java script

June 13, 2016 72
In this post I will discuss about onchange events.

What is onchange event?
The onchange event occurs when the value of an element has been changed.
For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

onChange specifies script code to run when the data in the input field changes. The onChange event is triggered when the contents of the field changes.

In this example if you type some thing in Quantity filed and click on anywhere on the page it will automatically update Total.








We can handle onchange events in different ways.

1. After entering quantity we can simulate clicking TAB button. But this is approach will not work always.

2. By using Java script we can trigger onchange event.


Using Java script to trigger onchange event...


((JavascriptExecutor)driver).executeScript("arguments[0].onchange()", driver.findElement(By.name("vn_qty")));

Below is the sample script.










March 3, 2016

Advanced Xpath with Examples

March 03, 2016 59
Here i am going to discuss about advanced usage of xpaths..
I will provide examples how to use xpath Axes.

Descendants
A node's children, children's children, etc.
In the following example; descendants of the form element are the div, title, author, year, and price elements


<form>

<div>
  
<title>Harry Potter</title>
  
<author>J K. Rowling</author>
  
<year>2005</year>
  
<price>29.99</price>
</div>

</form>


Here is Example:





If you want to find descendants of Div tag you need to use below syntax

//div[@id='browse-category']/descendant::*

If you want a specific element from descendants then use below syntax

Here i want to identify Payment link using descendant.

//div[@id='browse-category']/descendant::a[@data-category='Payment']

In the above example descendant will search for child elements and child's child elements as well.

UL is the child element for DIV and LI is the child element for UL and A is child element for LI. As we used descendant it will check for the matching element.



Following:
Selects everything in the document after the closing tag of the current node.


selects all elements after closing tag of P

//p[@class='fk-font-14']/following::*




if you want a specific element using following below is the example

//p[@class='fk-font-14']/following::div[@id='fk-mainfooter-id']


Following-sibling:
Selects all siblings after the current node.
//div[@id='browse-category']/ul/li/following-sibling::*

if you want a specific element then

//form[@class='faqsearchform']/following-sibling::div





Preceding :
Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes

preceding-sibling
Selects all siblings before the current node

Here is the example:

//div[@id='browse-category']/preceding-sibling::form





Now Lets see a real time example how to use the above mentioned xpath Axes:

Below is scenario:


  1. Navigate to flipkart
  2. add two products to cart
  3. I want to remove one product based on its name.




Simple xpath without using product name --- //a[@class='cart-remove-item fk-inline-block fk-uppercase'] but it always identifies first Remove button.


First Step: I will identify xpath for product Name

//span[text()='HP 15-af114AU Notebook(AMD Quad Core A8/ 4GB/...']

From there onward using xpath Axes i need to identify Remove link.

By loooking at DOM we can understand that there are two TR tags 
in one TR --we have product details and in another TR we have remove link.

so i have to traverse to second TR.

Second Step: Inorder to do that i need to traverse to parent element of span

//span[text()='HP 15-af114AU Notebook(AMD Quad Core A8/ 4GB/...']/ancestor::tr[1]

Third Step: from there traverse to sibling of TR
//span[text()='HP 15-af114AU Notebook(AMD Quad Core A8/ 4GB/...']/ancestor::tr[1]/following-sibling::tr

Fourth Step: From there traverse to tag A which has link text of Remove..here is the final xpath

//span[text()='HP 15-af114AU Notebook(AMD Quad Core A8/ 4GB/...']/ancestor::tr[1]/following-sibling::tr
/descendant::a[text()='Remove']


Hope this is useful in writing advanced xpaths....if you have any questions please do comment and I will be happy to help in you in writing xpaths..