Selenium Interview Questions

Q1. What are the annotations used in TestNG ?
Ans – @Test, @Before Suite, @After Suite, @Before Test, @After Test, @Before Class, @After Class, @Before Method, @After Method.

Q2. How do you read data from excel ?
Ans –

FileInputStream fis = new FileInputStream(“path of excel file”);
 Workbook wb = WorkbookFactory.create(fis);
 Sheet s = wb.getSheet(“sheetName”);
 String value = s.getRow(rowNum).getCell(cellNum).getStringCellValue();


Q3. What is the use of xpath?
Ans – it is used to find the WebElement in web page. It is very useful to identify the dynamic web elements.

Q4. What are different types of locators ?
Ans-  There are 8 types of locators and all are the static methods of the By class.,, By.tagName(), By.className(), By.linkText(), By.partialLinkText(), By.xpath, By.cssSelector().

Q5. What is the difference between Assert and Verify?
Ans- Assert- it is used to verify the result. If the test case fail then it will stop the execution of the test case there itself and move the control to other test case.
Verify- it is also used to verify the result. If the test case fail then it will not stop the execution of that test case.

Q6. What is the alternate way to click on login button?
Ans- use submit() method but it can be used only when attribute type=submit.

Q7. How do you verify if the checkbox/radio is checked or not ?
Ans-  We can use isSelected() method.
Syntax –

driver.findElement(By.xpath("xpath of the checkbox/radio bdriver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();utton")).isSelected();

If the return value of this method is true then it is checked else it is not.

Q8. How do you handle alert pop-up ?
Ans- To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle then move control back to main page.

String mainPage = driver.getWindowHandle();
 Alert alt = driver.switchTo().alert(); → to move control to alert popup
 alt.accept(); ---> to click on ok.
 alt.dismiss(); ---> to click on cancel.

Then move the control back to main web page-

driver.switchTo().window(mainPage); → to switch back to main page.

Q9. How do you launch IE/chrome browser?
Ans- Before launching IE or Chrome browser we need to set the System property.
To open IE browser →

System.setProperty(“”,”path of the iedriver.exe file ”);
 WebDriver driver = new InternetExplorerDriver();

To open Chrome browser →

System.setProperty(“”,”path of the chromeDriver.exe file ”);
 WebDriver driver = new ChromeDriver();

Q10. How to perform right click using WebDriver?
Ans- use Actions class.

Actions act = new Actions(driver); // where driver is WebDriver type

Q11. How do perform drag and drop using WebDriver?
Ans- use Action class.

Actions act = new Actions(driver);
WebElement source = driver.findElement(By.xpath(“ -----”)); //source ele which you want to drag
WebElement target = driver.findElement(By.xpath(“ -----”)); //target where you want to drop

Q12. Give the example for method overload in WebDriver.
Ans- frame(string), frame(int), frame(WebElement).

Q13. How do you upload a file?
Ans- To upload a file we can use sendKeys() method.
Syntax – driver.findElement(By.xpath(“input field”)).sendKeys(“path of the file which u want to upload”);

Q14. How do you click on a menu item in a drop down menu?
Ans- if that menu has been created by using select tag then we can use the methods selectByValue() or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.
If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.

Q15. How do you simulate browser back and forward ?
Ans- driver.navigate().back();

Q16. How do you get the current page URL ?
Ans- driver.getCurrentUrl();

Q17. What is the difference between ‘/’ and ‘//’ ?
Ans-    //- it is used to search in the entire structure.
/- it is used to identify the immediate child.

Q18. What is the difference between findElement and findElements?
Ans- Both methods are abstract method of WebDriver interface and used to find the WebElement in a web page.
findElement() –  it used to find the one web element. It return only one WebElement type.
findElements()-  it used to find more than one web element. It return List of  WebElements.

Q19. How do you achieve synchronization in WebDriver ?
Ans- We can use implicit wait.
Syntax-  driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
Here it will wait for 10sec if while execution driver did not find the element in the page immediately. This code will attach with each and every line of the script automatically. It is not required to write every time. Just write it once after opening the browser.

Q20. Write the code for Reading and Writing to Excel through Selenium ?

Ans-     FileInputStreamfis = new FileInputStream(“path of excel file”);
Workbook  b          = WorkbookFactory.create(fis);
Sheet   s                    = wb.getSheet(“SheetName”);
String  value             = s.getRow(rowNum).getCell(cellNum).getStringCellValue();  // read data
s.getRow(rowNum).getCell(cellNum).setCellValue();                                               //write data
FileOutputStream fos = new FileOutputStream(“path of file”);
wb.write(fos);                                                                                                             //save file

Q21. How to get typed text from a textbox ?
Ans- use getAttribute(“value”) method by passing arg as value.
syntax-  String typedText  = driver.findElement(By.xpath(“xpath of box”)).getAttribute(“value”));

Q22. What are the different exceptions you got when working with WebDriver ?
Ans-  ElementNotVisibleException, ElementNotSelectableException, NoAlertPresentException, NoSuchAttributeException, NoSuchWindowException, TimeoutException, WebDriverException etc.

Q23. What are the languages supported by WebDriver ?
Ans- Python, Ruby, C# and Java are all supported directly by the development team. There are also webdriver implementations for PHP and Perl.

Q24. How do you clear the contents of a textbox in selenium ?
Ans- use clear() method.
syntax-  driver.findElement(By.xpath(“xpath of box”)).clear();

Q25. What is a Framework ?
Ans- A framework is  set of automation guidelines  which help in
Maintaining consistency of Testing, Improves test structuring, Minimum usage of code, Less Maintenance of code, Improve re-usability, Non Technical testers can be involved in code, Training period of using the tool can be reduced,  Involves Data wherever appropriate.
There are five types of framework used in software automation testing:
1-Data Driven Automation Framework
2-Method Driven Automation Framework
3-Modular Automation Framework
4-Keyword Driven Automation Framework
5-Hybrid Automation Framework ,its basically combination of different frameworks. (1+2+3).

Q26. What are the prerequisites to run selenium webdriver?
Ans- JDK, Eclipse, WebDriver(selenium standalone jar file), browser, application to be tested.

Q27. What are the advantages of selenium webdriver?
Ans- a) It supports with most of the browsers like Firefox, IE, Chrome, Safari, Opera etc.
b)  It supports with most of the language like Java, Python, Ruby, C# etc.
b) Doesn’t require to start server before executing the test script.
c) It has actual core API which has binding in a range of languages.
d) It supports of moving mouse cursors.
e) It support to test iphone/Android applications.

Q28. What is WebDriverBackedSelenium ?
Ans- WebDriverBackedSelenium is a kind of class name where we can create an object for it as below:                                            Selenium wbdriver= new WebDriverBackedSelenium(WebDriver object name, “URL path of website”).
The main use of this is when we want to write code using both WebDriver and Selenium RC , we must use above created object to use selenium commands.

Q29. How to invoke an application in webdriver ?
Ans- driver.get(“url”); or driver.navigate().to(“url”);

Q30. What is Selenium Grid ?
Ans- Selenium-Grid allows you to run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines, different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.

Q31. How to get the number of frames on a page ?
Ans- List <WebElement>framesList = driver.findElements(By.xpath(“//iframe”));
intnumOfFrames = frameList.size();



Q32. How do you simulate scroll down action ?
Ans- use java script to scroll down-
JavascriptExecutorjsx = (JavascriptExecutor)driver;
jsx.executeScript(“window.scrollBy(0,4500)”, “”); //scroll down, value 4500 you can change as per your req
jsx.executeScript(“window.scrollBy(450,0)”, “”); //scroll up
public class ScrollDown {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
JavascriptExecutorjsx = (JavascriptExecutor)driver;
jsx.executeScript(“window.scrollBy(0,4500)”, “”); //scroll down
jsx.executeScript(“window.scrollBy(450,0)”, “”); //scroll up

Q33. What is the command line we have to write inside a .bat file to execute a selenium project when we are usingTestNG?

Ans- java -cpbin;ars/* org.testng.TestNG testng.xml

Q34. Which  is the package which is to be imported while working with WebDriver ?
Ans-  org.openqa.selenium

Q35. How to check if an element is visible on the web page ?
Ans- use isDisplayed() method. The return type of the method is boolean. So if it return true then element is     visible else not visible.
Syntax – driver.findElement(By.xpath(“xpath of elemnt”)).isDisplayed();

Q36. How to check if a button is enabled on the page ?
Ans- use isEnabled() method. The return type of the method is boolean. So if it return true then button is     enabled else not enabled.
Syntax – driver.findElement(By.xpath(“xpath of button”)).isEnabled();

Q37. How to check if a text is highlighted on the page ?

Ans- To identify weather color for a field is different or not-
String color = driver.findElement(By.xpath(“//a[text()=’Shop’]”)).getCssValue(“color”);
String backcolor = driver.findElement(By.xpath(“//a[text()=’Shop’]”)).getCssValue(“background-color”);
Here if both color and backcolor different then that means that element is in different color.

Q38. How to check the checkbox or radio button is selected ?
Ans- use  isSelected() method to identify. The return type of the method is boolean. So if it return true then         button is selected else not enabled.
Syntax – driver.findElement(By.xpath(“xpath of button”)).isSelected();

Q39. How to get the title of the page ?
Ans- use getTitle() method.
Syntax- driver.getTitle();


Q40. How do u get the width of the textbox ?

Ans-     driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getWidth();
driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getHeight();

Q41. How do u get the attribute of the web element ?

Ans- driver.getElement(By.tagName(“img”)).getAttribute(“src”) will give you the src attribute of this tag.     Similarly, you can get the values of attributes such as title, alt etc.
Similarly you can get CSS properties of any tag by using getCssValue(“some propety name”).

Q42. How to check whether a text is underlined or not ?
Ans- Identify by getCssValue(“border-bottom”) or sometime getCssValue(“text-decoration”) method if the
cssValue is ‘underline’ for that WebElement or not.
ex- This is for when moving cursor over element that is going to be underlined or not-
public class UnderLine {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String cssValue= driver.findElement(By.xpath(“//a[text()=’Hindi’]”)).getCssValue(“text-decoration”);
Actions act = new Actions(driver);
String cssValue1= driver.findElement(By.xpath(“//a[text()=’Hindi’]”)).getCssValue(“text-decoration”);
System.out.println(“value over”+cssValue1);

Q43. How to change the URL on a webpage using selenium web driver ?

Ans-  driver.get(“url1”);

Q44. How to hover the mouse on an element ?
Ans- Actions act = new Actions(driver);
act.moveToElement(webelement); //webelement on which you want to move cursor

Q45. What is the use of getOptions() method ?
Ans- getOptions() is used to get the selected option from the dropdown list.

Q46. What is the use of deSelectAll() method ?
Ans- It is used to deselect all the options which have been selected from the dropdown list.

Q47. Is WebElement an interface or a class ?
Ans- WebDriver is an Interface.

Q48. FirefoxDriver is class or an interface and from where is it inherited ?
Ans- FirefoxDriver is a class. It implements all the methods of  WebDriver interface.

Q49. Which is the super interface of webdriver ?
Ans-  SearchContext.

Q50. What is the difference b/w close() and quit()?
Ans- close() – it will close the browser where the control is.
quit()  – it will close all the browsers opened by WebDriver.

Q51. How to enter text without using sendkeys() ?
Ans – Yes we can enter text without using sendKeys() method. We have to use combination of javascript and wrapper classes with WebDriver extension class, check the below code-

public static void setAttribute(WebElement element, String
attributeName, String value)
WrapsDriverwrappedElement = (WrapsDriver) element;
JavascriptExecutor driver = (JavascriptExecutor)
arguments[2])”, element, attributeName, value);

call the above method in the test script and pass the text field attribute and pass the text you want to enter.

Q52. There is a scenario whenever “Assert.assertEquals()” function fails automatically it has to take screenshot. How can you achieve this ?
Ans- By using EventFiringWebDriver.

EventFiringWebDriver eDriver=new EventFiringWebDriver(driver);
File srcFile = eDriver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File(imgPath));

Q53. How do you handle https website in selenium
Ans- By changing the setting of FirefoxProfile.
public class HTTPSSecuredConnection {
public static void main(String[] args){
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(profile);

Q54. How to login into any site if its showing any authentication popup for user name and pass ?
Ans – pass the username and password with url.
Syntax- http://username:[email protected]
ex- http://creyate:[email protected]

Q55. What is the name of Headless browser.
Ans- HtmlUnitDriver.

Q56. Open a browser in memory means whenever it will try to open a browser the browser page must not come and can perform the operation internally.
Ans- use HtmlUnitDriver.
public class Memory {
public static void main(String[] args) {
HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Q57. What are the benefits of using TestNG?
Ans- 1- TestNG allows us to execute of test cases based on group.
2- In TestNG Annotations are easy to understand.
3-Parallel execution of Selenium test cases is possible in TestNG.
4- Three kinds of report generated
5- Order of execution can be changed
6- Failed test cases can be executed
7- Without having main function we can execute the test method.
8- An xml file can be generated to execute the entire test suite. In that xml file we can rearrange our execution order and we can also skip the execution of particular test case.

Q58. How do you take screen shot without using EventFiringWebDriver ?
File srcFile = ((TakeScreenshot)driver).getScreenshotAs(OutputType.FILE); //now we can do anything with this screenshot
like copy this to any folder-
FileUtils.copyFile(srcFile,new File(“folder name where u want to copy/file_name.png”));

Q59. How do you send ENTER/TAB keys in webdriver?
Ans- use click() or submit() [submit() can be used only when type=’submit’]) method

for ENTER.
Or act.sendKeys(Keys.ENTER);
For Tab-
where act is Actions class type. ( Actions act = new Actions(act); )

Q60. What is Datadriven framework & Keyword Driven?

Ans – Datadriven framework- In this Framework , while Test case logic resides in Test Scripts, the Test Data is separated and kept outside the Test Scripts. Test Data is read from the external files (Excel File) and are loaded into the variables inside the Test Script. Variables are used both for Input values and for Verification values.

Keyword Driven framework- The Keyword-Driven or Table-Driven framework requires the development of data tables and keywords, independent of the test automation tool used to execute them . Tests can be designed with or without the Application. In a keyword-driven test, the functionality of the application-under-test is documented in a table as well as in step-by-step instructions for each test.

Q61. While explaining the framework, what are points which should be covered ?

Ans-    1.What is the frame work.
2. Which frame work you are using.
3. Why This Frame work.
4. Architecture.
5. Explanation of every component of frame work.
6. Process followed in frame work.
7. How & when u execute the frame work.
8. Code (u must write code and explain).
9. Result and reporting .
10. You should be able to explain it for 20 Minutes.

Q62. How to switch back from a frame ?

Ans- use method defaultContent().
Syntax – driver.switchTo().defaultContent();

Q63. How to type text in a new line inside a text area ?
Ans- Use \n for new line.
ex-  webelement.sendKeys(“Sanjay_Line1.\n Sanjay_Line2.”);
it will type in text box as

Q64. What is the use of AutoIttool ?
Ans- Some times while doing testing with selenium, we get stuck by some interruptions like a window based pop up. But selenium fails to handle this as it has support for only web based application. To overcome this problem we need to use AutoIT along with selenium script. AutoIT is a third party tool to handle window based applications. The scripting language used is in VBScript.

Q65. How to perform double click using WebDriver ?
Ans- use doubleClick() method.
Syntax- Actions act = new Actions(driver);

Q66. How to press Shift+Tab ?
Ans-     String press = Keys.chord(Keys.SHIFT,Keys.TAB);

Q67. What is the use of contextClick() ?
Ans- It is used to right click.

Q68. What is the difference b/w getWindowHandles() and getWindowHandle() ?
Ans- getWindowHandles()- is used to get the address of all the open browser and its return type is Iterator<String>.
getWindowHandle()- is used to get the address of the current browser where the conrol is and return type is String.

Q69. How do you accommodate project specific methods in your framework ?
Ans- 1st go through all the manual test cases and identify the steps which are repeating. Note down such steps and make them as methods and write into ProjectSpecificLibrary.

Q70. What are different components of your framework ?
Ans- Library- Assertion, ConfigLibrary, GenericLibrary, ProjectSpecificLibrary, Modules.
Drivers folder, Jars folder, excel file.

Q71. What are the browsers supported by Selenium IDE ?
Ans-  MozillaFireFox only. Its an Firefox add on.

Q72. What are the limitations of Selenium IDE ?
Ans- a)-  It does not supports looping or conditional statements. Tester has to use native languages to write logic in the test case.
b)-  It does not supports test reporting, you have to use selenium RC with some external reporting plugin like TestNG or JUint to get test execution report.
c)- Error handling is also not supported depending on the native language for this.
d) Only support in Mozilla FireFox only. Its an Firefox add on.

Q73. How to check all checkboxes in a page ?
Ans- List<webElement>  chkBox = driver.findElements(By.xpath(“//htmltag[@attbute=’checkbox’]”));
for(inti=0; i<=chkBox.size(); i++){

Q74. Count the number of links in a page.
Ans- use the locator By.tagName and find the elements for the tag //a then use loop to count the number of elements found.
Syntax-  int  count = 0;
List<webElement>  link = driver.findElements(By.tagName(“a”));
System.out.println(link.size());  // this will print the number of links in a page.

Q75. How do you identify the Xpath of element on your browser ?
And- to find the xpath , we use Firebug addons on firefox browser and to identify the xpath written we use Firepathaddons.
Syntax- //htmltag[@attname=’attvalue’] or //html[text()=’textvalue’] or //htmltag[contains(text(),’textvalue’)] or //htmltag[contains(@attname,’attvalue’)]

Q76. What is Selenium Webdriver ?
Ans- WebDriver is the name of the key interface against which tests should be written in Java. All the methods of WebDriver have been implementated by RemoteWebDriver.

Q77. What is Selenium IDE
Ans- Selenium IDE is a complete integrated development environment (IDE) for Selenium tests. It is implemented as a Firefox Add-On, and allows recording, editing, and debugging tests. It was previously known as Selenium Recorder.
Scripts may be automatically recorded and edited manually providing auto completion support and the ability to move commands around quickly.
Scripts are recorded in Selenese, a special test scripting language for Selenium. Selenese provides commands for performing actions in a browser (click a link, select an option), and for retrieving data from the resulting pages.

Q78. What are the flavors of selenium ?
Ans- selenium IDE, selenium RC, Selenium WebDriver and Selenium Grid.

Q79. What is selenium ?
Ans- It’s an open source Web Automation Tool. It supports all types of web browsers. Despite being open source its actively developed and supported.

Q80. Advantages of selenium over other tools ?
Ans- 1) Its free of cost,
it supports many languages like Java, C#, Ruby, Python etc.,
it allows simple and powerful DOM-level testing etc.

Q81. What is main difference between RC and webdriver ?
Ans- Selenium RC injects javascript function into browsers when the web page is loaded.
Selenium WebDriver drives the browser using browser’s built-in support.

Q82. Why you choose webdriver over RC ?
Ans-  1) Native automation faster and a little less prone to error and browser configuration,
2) Does not Requires Selenium-RC Server to be running
3) Access to headless HTMLUnitDriver can allow really fast tests
4) Great API etc.

Q83. Which one is better xpath or CSS ?
Ans- xpath.

Q84. How will you handle dynamic elements ?
Ans- By writing relative xpath.




Q85. what are the different assertions or check points used in your script?
Ans- The common types of validations are:
a)  Is the page title as expected
b) Validations against an element on the page
c)  Does text exist on the page
d) Does a javascript call return an expected value
method used for validation – Assert.assertEquals();

Q86. What is actions class in webdriver?
Ans- Actions class is used to control the actions of mouse.

Q87. What is the difference between before method and before class ?
Ans- @BeforeMethod- this will execute before every @Test method.
@BeforeClass- this will execute before every class.

Q88. What are the different attributes for @Test annotation?
Ans-  alwaysRun, dataProvider, dependsOnMethods, enabled, expectedExceptions, timeOut etc.
ex- @Test(expectedExceptions = ArithmeticException.class),
@Test(timeOut = 2000).

Q89. Can we run group of test cases using TestNG ?
Ans- yes.

Q90. What is object repository ?
Ans- An object repository is a very essential entity in any UI automation tool. A repository allows a tester to store all the objects that will be used in the scripts in one or more centralized locations rather than letting them be scattered all over the test scripts. The concept of an object repository is not tied to WET alone. It can be used for any UI test automation. In fact, the original reason why the concept of object repositories were introduced was for a framework required by QTP.

Q91. What are oops concepts ?
Ans- a) Encapsulation, b) Abstraction, c)Polymorphism, d) Inheritance.

Q92. What is inheritance ?
Ans- Inherit the feature of any class by making some relations between the class/interface is known as inheritance.

Q93. What is difference between overload and override ?
Ans- The methods by passing different arguments list/type is known as overloading of methods while having the same method signature with different method body is known as method overriding.

Q94. Does java supports multiple inheritance?
Ans- Interface supports multiple inheritance but class does not support.

Q95. Write a java program for swapping of two numbers ?
Ans- public class Swapping{
public static void main(String[] args){
Scanner in = new Scanner(;
System.out.println(“enter the 1st num”);
int a = in.nextInt();
System.out.println(“enter the 2nd num”);
int b = in.nextInt();
System.out.println(“before swapping a=”+a+” and b= ”+b);
int x = a;
a = b;
b = x;
System.out.println(“After swapping a=”+a+” and b= ”+b);

Q96. Write a java program for factorial of a given number.
Ans- public class Factorial{
public static void main(String args[]){
Scanner in = new Scanner(;
System.out.println(“enter the num for which u want the factorial”);
int num = in.nextInt();
for(int i=num-1; i>0; i– ){
num = num*i;

Q97. What are different access modifiers in Java ?
Ans- private, default, protected and public.

Q98. Why do we go for automation testing ?
Ans – Reasons-
a) Manual testing of all work flows, all fields, all negative scenarios is time and cost consuming.
b) It is difficult to test for multi lingual sites manually.
c) Automation does not require human intervention. We can run automated test unattended(Overnight).
d) Automation increases speed of test execution.
e) Automation helps increase test coverage.
f) Manual testing can become boring and hence error prone.

Q99.  What is testing strategy ?
Ans –  A Test Strategy document is a high level document and normally developed by project manager. This document defines “Software Testing  Approach” to achieve testing objectives. The Test Strategy is normally derived from the Business Requirement Specification document.

Q100. write a code to make use of assert if my username is incorrect.


Assert.assertEquals(expUserName, actUserName);

catch(Exception e)

Syste.out.println(“name is invalid”);






  1. TestNg Annotations




  1. What are desired capabilities?


Desired capabilities are used to set the Properties for the Wbdriver.

Typical use case would be to set the path for the firefoxdriver if your local connection doesn’t correspond to the default


  1. Which is the best way to locate an element?


->Finding elements by ID is usually going to be the fastest option,

ex: document.getElementById(),

->Finding elements by XPath is useful for finding elements using very complex selectors

ex: driver.findElement(By.xpath(“WebElement Path”));


->If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors

ex: driver.findElement(By.CssSelector(“WebElement Path”));


  1. What are the features of TestNG?


-Test Ng is a testing framework designed to simply range of testing needs, from unit testing to integration testing.

-You can use test suites to automatically generating Reports.


  1. In what situation selenium finding element get fails?


-finding Dinamic webelements/Id

-ElementLoading Issue


  1. What’s the basic use of Firefox profiles & how can we use them using selenium?


-A profile in firefox is a collection of bookmarks, browser settings and history.

-we use them to changes the user agent, changing default download directory.


  1. How to overcome same origin policy through web driver..?


->Proxy Server.


DesiredCapabilities dc=new DesiredCapabilities.firefox();

dc.setcapability(CapabilityType.PROXY,”Your desired proxy”);

webdriver driver=new firefoxDriver(dc);


8.How to put text in Facebook search box using selenium web driver.?


-> driver.findElement(By.Xpath(“/div[contains(@class,’_586i’)]”)).sendKeys(“”);


9.What is Error Collector in TestNG?


-This class allows the collection of errors during the process of retriving the test data.



  1. How can we get the font size, font color, font type used for a particular text on a web page using Selenium web driver?


– driver.findelement(By.Xpath(“Xpath “).getcssvalue(“font-size);

– driver.findelement(By.Xpath(“Xpath “).getcssvalue(“font-colour);

– driver.findelement(By.Xpath(“Xpath “).getcssvalue(“font-type);

– driver.findelement(By.Xpath(“Xpath “).getcssvalue(“background-colour);




Page object model  :

  • Page Object Modelis a design pattern to create Object Repository for web UI elements.
  • Under this model, for each web page in the application there should be corresponding page class.
  • This Page class will find the Web Elements of that web page and also contains Page methods which perform operations on those Web Elements.
  • Name of these methods should be given as per the task they are performing i.e., if a loader is waiting for payment gateway to be appear, POM method name can be waitForPaymentScreenDisplay().

Advantages of POM

  1. Page Object Patten says operations and flows in the UI should be separated from verification. This concept makes our code cleaner and easy to understand.
  2. Second benefit is the object repository is independent of testcases, so we can use the same object repository for a different purpose with different tools. For example, we can integrate POM with TestNG/JUnit for functional testing and at the same time with JBehave/Cucumberfor acceptance testing.
  3. Code becomes less and optimized because of the reusable page methods in the POM classes.
  4. Methodsget more realistic names which can be easily mapped with the operation happening in UI. i.e. if after clicking on the button we land on the home page, the method name will be like ‘gotoHomePage()’.



Final Keyword:


If you make any variable as final, you cannot change the value of final variable


Variable: Stop value change

Method: Stop method overloading

Class   : Stop Inheritance



It is a special type of method that is used to initialize the object.

Java constructor is invoked at the time of object creation.

There are basically two rules defined for the constructor.

  1. Constructor name must be same as its class name
  2. Constructor must have no explicit return type




Leave a Reply

Your email address will not be published. Required fields are marked *