Working with frames,frameSet,iframes in Selenium WebDriver using CoreJava(TargetLocator)







Handling Frames using TargetLocator(switchTo())!!!
Generally when ever we open the page we don't find the frames for every application. Ex: Facebook.com doesn't have frames. If we want to confirm whether frames are implemented for the web application we can follow 
steps mentioned below:
1. Open Firefox
2. Enter the Url http://www.facebook.com
3. Click on Firebug plugin.
4. Navigate to Firepath plugin.
5. Check the screenshot as mentioned below. Based on this we can decide whether the frames are implemented for this application.







Also, if we want to perform any action say enter the text in the textbox available in the Frame. we have to use following methods:
driver.switchTo().frame(int index)- index starts from zero.
or
driver.switchTo().frame(String framename)
Download the html source code from these links:
1. Frames.html
 https://tobeanexpert.blogspot.com/b/post-preview?token=w7uC8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.lYohA8_aM5FeDVfOJAyW_A&postId=629786504598294227&type=POST
2. frame_a.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=DHWE8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.OU_N6UQ4tzlB7XypI_Se_A&postId=1277459784965833367&type=POST
3. frame_b.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=cluH8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.1JCsNYQVBnWsiXWYmOcl1Q&postId=3121611285388662540&type=POST
4. frame_c.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=vo6H8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.DjH_UeWElg9eQ_06IQETBw&postId=7113507276382232086&type=POST
After downloading the html examples from the (1-4) links opening the Frames.html it looks like web-application the finally as below






Program: HandlingFrames.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HandlingFrames {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/Selenium/HTML/Frames.html");
//switch to a particular frame from the topwindow using index
driver.switchTo().frame(2);
driver.findElement(By.id("Frame3txt")).clear();
driver.findElement(By.id("Frame3txt")).sendKeys("in frame3");
//Switches the frame to a top window
driver.switchTo().defaultContent();
driver.switchTo().frame("frame_a");
//driver.switchTo().frame(driver.findElement(By.id("Frame1txt")));
driver.findElement(By.id("Frame1txt")).clear();
driver.findElement(By.id("Frame1txt")).sendKeys("in frame1");
//Switches the frame to a top window
driver.switchTo().defaultContent();
driver.switchTo().frame("frame_b");
driver.findElement(By.id("Frame2txt")).clear();
driver.findElement(By.id("Frame2txt")).sendKeys("in frame2");
}
}
Handling iFrames using TargetLocator(switchTo())!!!
Usually idenfitying Frames is easy becoz when defining the frames the developer provides the properties of the frame say name and id.
In the below examples the frame name is provided which is easy we can switch using driver.switchTo().frame("frame_a");
<!DOCTYPE html>
<html>

<frameset cols="25%,*,25%">
  <frame src="frame_a.html" name="frame_a">
  <frame src="frame_b.html" name="frame_b">
  <frame src="frame_c.html" name="frame_c">
</frameset>

</html>
But in the case of iframe its totally different. No properties defined for iframe then how do we switch??? 
<!DOCTYPE html>
<html>
<body>
<iframe width="100%" height="300px" src="iframedemo.htm">
</iframe>
</body>
</html>
To understand this better check the page source of the html file "iframedemo.htm". It contains one textbox box named "frame1txt".
Now we can switch to this iframe using the following method:
driver.switchTo().frame(driver.findElement(By.name("frame1txt")));
<html>
<body style="background-color:#F5DEB3">
<h1>This page is displayed in an iframe</h1>
Username:<input type="text" name="frame1txt" id="frame1txt">
</body>
</html>
Download the html source code from these links:
1. Handlingiframes.html
2. iframedemo.htm








Program: HandlingIFrames.java
public class HandlingIFrames {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/Selenium/HTML/Frames.html");
//switch to a particular iframe using the webElement
driver.switchTo().frame(driver.findElement(By.name("frame1txt")));
   driver.findElement(By.name("frame1txt")).sendKeys("selenium");
 }
}

References:http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.TargetLocator.html

Selenium WebDriver- Debugging Code (Breakpoints) - Java Debugging with Eclipse









Most of us interested to know, how the code is getting executed. Some times, even if we write the code with out having any syntax errors also during execution we face issues which requires debugging of the code.
As Web-driver script executes fast, if we want to execute the Web-driver  code line-by-line and verify the Output can be achieved using the Debug Mode in Eclipse.
Lets start. I have written a very simple example in Selenium Webdriver to retrieve the text in Facebook as highlighted in the below image.









Facebook.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Facebook {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
driver.get("https://www.Facebook.com");
String actual = driver.findElement(By.xpath("//span[text()=' See photos and updates ']")).getText();
System.out.println(actual);
String expected = " See photos and updates";

if(actual.equals(expected))
{
System.out.println("Actual is equal to Expected TC - Pass");

}
else
System.out.println("Actual is not equal to Expected TC - Fail");
}

}
There are no syntax errors in the code. Please try to execute the code as shown below:








Output:
Actual is not equal to Expected TC - Fail
In the above scenario the TC should pass. But we are getting response as TC-Fail.
So, how do we identify the issue. What is the reason for failure.
We have to use Debug mode to identify the root-cause for this issue.
Debug - Step1- Insert BreakPoint
Right-click at the line number 10 and select the first option - 'Toggle Breakpoint'. It means we are inserting the Breakpoint, so we can verify the values in the variable at run time.
In our case we can verify the value stored in the 'actual'.










Step2-Run Facebook.java in Debug mode










Step3- Debug Perspective opens as shown below
Select the checkbox-'Remember by decision' and click on 'Yes' button.









The Debug perspective opens, it has three tabs Variables,Breakpoints,Expressions.








Out of three tabs- Expressions tab is required to view the values at run-time.In Debug perspective if you are unable to identify this tab. You to follow the steps as show below:






Navigate to Expression tab and click on 'Add new expression' enter 'actual' as shown below:









Click on Step-Over to move to next step. Verify the 'actual' value in the Expression tab.Also add few more expressions as shown below:
Actual String length-> actual.length()
Expected String length()->expected.length()








Click on Step-Over to move to next step. Verify all the values as shown below:







Conclusion
The length of expected String is 23.
The length of actual String is 22. 
So there is an issue in expected string. In the program we provided the String expected =" See photos and updates";
There is an unnecessary space added in the string. It should be changed to String expected ="See photos and updates";
by removing the unwanted spaces.
Once identify the issue click on terminate button as shown below.







Change the Perspective from Debug Mode to Java Mode.







Remove all the breakpoints.

Selenium Automation Resume - Highlights Roles & Responsibilities

Resume Highlights:
--------------------------
Having 7+ years of experience in Manual and Automation Testing.
Experience in Selenium WebDriver using Core Java.
Experience in designing the Java Frameworks like Testng.
Experience in designing the automation frameworks like Data-driven and Modular
Driven using Page Object Model.
Hands-on-Experience in performing cross browser testing using Testng and Grid.
Good Knowledge in HTML and XML.
Experience in understanding and writing testcases.

Responsbilities:
------------------
Performed regression and sanity testing for the project.
Raised the bugs in Bugzilla/Jira.
Provide the logs and screenshots while raising the bugs which gives
more information to developer to fix the defect on-time.
Design the Framework using ...
Automate the testcases using Selenium Webdriver with Java Framework Testng.
Report the results to the stake holders.
Invovled in the module of the project.
Worked effeciently to make sure the project is released on time with high quality.