Selenium Interview Question 9

41 : What kind of software testings are possible using selenium WebDriver? We can use It for any other purpose except testing activity?
Answer : Generally we are using selenium WebDriver for functional and regression testing of software web applications.


42 : Give me any five different xPath syntax to locate bellow given Input element.

<input id="fk-top-search-box" class="search-bar-text fk-font-13 ac_input" type="text" autofocus="autofocus" value="" name="q" />
Answer : Five xPath syntax for above element of software web application page are as bellow.

//input[@id='fk-top-search-box']
//input[contains(@name,'q')]
//input[starts-with(@class, "search-bar-text")]
//input[@id='fk-top-search-box' or @name='q']
//input[starts-with(@id, 'fk-top-search-box') and contains(@class,'fk-font-13')]

See detailed tutorial on
 How To Locate XPath Of Element.

43 : Can you tell me two drawbacks of xPath locators as compared to cssSelector locator?
Answer : Two main disadvantage of xPath locator as compared to cssSelector locator are as bellow.
  • It Is slower than cssSelector locator.
  • xPath which works In one browser may not work In other browser for same page of software web application because some browsers (Ex. IE) reads only Lower-cased tag name and Attribute Name. So If used It In upper case then It will work In Firefox browser but will not work In IE browser. Every browser reads xPath In different way. In sort, do not use xPath locators In your test cases of software web application If you have to perform cross browser testing using selenium WebDriver software testing tool.
44 : Why xPath locator Is much more popular than all other locator types In WebDriver?
Answer : xPath locators are so much popular In selenium webdriver test case development because
  • It Is very easy to learn and understand for any new user.
  • There are many functions to build xPath In different ways like contains, starts-with etc.. So If one Is not possible you will have always another option to build xPath of any element.
  • Presently many tools and add-ons are available to find xpath of any element.
45 : Give me WebDriver's API name using which we can perform drag and drop operation.
Answer : That API's name Is Advanced User Interactions API using which we can perform drag and drop operation on page of software web application. Same API can help us to perform some other operations too like moveToElement, doubleClick, clickAndHold, moveToElement, etc..



47
 : Do you have faced any technical challenges with Selenium WebDriver software test automation?
Answer : Yes, I have faced bellow given technical challenges during selenium webdriver test cases development and running for software web application.
  • Sometimes (Not always), Some elements like text box, buttons etc. are taking more time(more than given Implicit wait time) to appear on page of software web application or to get enabled on page. In such situation, If I have used only Implicit wait then my test case can run fine on first run but It may fail to find element on second run. So we need provide special treatment for such elements so that webdriver script wait for element to be present or get enabled on page of software web application during test execution. We can use Explicit wait to handle this situation. You can find different explicit wait example links on THIS PAGE.
  • Handling dynamic changing ID to locate element Is tricky. If element's ID Is changing every time when you reload the software web application page and you have to use that ID In XPath to locate element then you have to use functions like starts-with(@id,'post-body-') or contains(@id,'post-body-') In XPath. Other alternate solutions to handle this situation are described in answer of Question 15 of THIS PAGE.
  • Clicking on sub menus which are getting rendered on mouse hover of main menu Is some what tricky. You need to use webdriver's Actions class to perform mouse hover operation. You can VIEW FULL EXAMPLE on how to generate mouse hover event on main menu.
  • If you have to execute your test cases In multiple browsers then one test case can run successfully In Firefox browser but same test case may fail In IE browser due to the timing related Issues (nosuchelement exception) because test execution In Firefox browser Is faster than IE browser. You can resolve this Issue by Increasing Implicit wait time when you run your test In IE browser.
  • Above Issue can arise due to the unsupported XPath In IE browser. In this case, You need to you OTHER ELEMENT LOCATING METHODS (ID, Name, CSSSelector etc.)to locate element.
  • Handling JQuery elements like moving pricing slider, date picker, drag and drop etc.. Is tricky. You should have knowledge of webdriver's Advanced User Interactions API to perform all these actions. You can find few example links for working with JQuery Items on THIS PAGE.
  • Working with multiple Windows, Frames, and some tasks like Extracting data from web table, Extracting data from dynamic web tableExtracting all Links from page, Extracting all text box from page are also tricky and time consuming during test case preparation.
  • There Is not any direct command to upload or download files from web page using selenium webdriver. For downloading files usign selenium webdriver, You need to create and set Firefox browser profile with webdriver test case. You can VIEW PRACTICAL EXAMPLE.
  • Webdriver do not have any built In object repository facility. You can do It using java .properties file to create object repository as described In THIS EXAMPLE
  • Webdriver do not have any built In framework or facility using which we can achieve bellow given tasks directly : 1. Capturing screenshots, 2. generating test execution log, 3. reading data from files, 4. Generating test result reports, Manage test case execution sequence. To achieve all these tasks, We have to use external services with webdriver like Log4J to generate log, Apache POI API to read data from excel files, Testng XSLT reports to generate test result reports. TestNG to manage test case execution, .properties file to create object repository. All these tasks are very time consuming. ON THIS PAGE, I have described how to create data driven framework step by step for selenium webdriver. That framework contains all above functionality.


48 : Can you tell me a syntax to close current webdriver Instance and to close all opened webdriver Instances?

Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
driver.close();

If there are opened multiple webdriver Instances and wants to close all of them then we can use webdriver's quit() method as bellow in software automation test.

driver.quit();

49 : Is It possible to execute javascript directly during software test execution? If Yes then tell me how to generate alert by executing javascript In webdriver script?

Answer :
Yes, we can execute javascript during webdriver software test execution. To generate alert, You can write bellow given code In your script.

JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Javascript Executed.');");

VIEW DIFFERENT EXAMPLES to see usage of WebDriver's JavascriptExecutor.

50 : Give me a syntax to read javascript alert message string, clicking on OK button and clicking on Cancel button.

Answer :
We can read alert message string as bellow.

String alrtmsg = driver.switchTo().alert().getText();

We can click on OK button of alert as bellow.

driver.switchTo().alert().accept();

We can click on Cancel button of alert as bellow.

driver.switchTo().alert().dismiss();


Selenium Interview Question 8

31 : Can you tell me the names of different projects of selenium software automation testing tool?
Answer : At present, Selenium software automation testing tool has four different projects as bellow.
  • Selenium IDE : It Is Firefox add-on which allows you to record and playback your software web application's tests In Firefox browser.
  • Selenium RC : It Is software web application automation tool which allows you to write your tests In many different programming languages.
  • Selenium WebDriver : It Is well designed object oriented API developed to automate web and mobile software application testing process. You can write your tests In different languages too In selenium webdriver.
  • Selenium Grid : Grid allows you to execute your tests In parallel by distributing them on different machines having different browser/OS combinations.

32 : I wants to use java language to create tests with Selenium WebDriver. Can you tell me how to get latest version of WebDriver?
Answer : You can download language specific latest released client drivers for selenium WebDriver software testing tool at http://docs.seleniumhq.org official website. For java language, You will get bunch of jar files In zip folder. And then you can add all those jar files In your project's java build path as a referenced libraries to get support of webdriver API.

33 : Can you tell me the usage of "submit" method In selenium WebDriver?
Answer : We can use submit method to submit the forms In selenium WebDriver software automation testing tool. Example : Submitting registration form, submitting LogIn form, submitting Contact Us form ect.. After filling all required fields, We can call submit method to submit the form. VIEW EXAMPLE.
34 : Do you have faced any Issue with "submit" method any time?
Answer : Yes, I have faced Issue like submit method was not working to submit the form. In this case, Submit button of form was located outside the opening <form> and closing </form> tags. In this case submit method will not works to submit the form.

Also If submit button Is located Inside opening
 <form> and closing </form> tags but that button's type tag's attribute Isn't submit then submit method will not work. It(type tag's attribute) should be always submit.

35 : What Is the syntax to type value In prompt dialog box's Input field using selenium WebDriver?
Answer : Prompt dialog Is just like confirmation alert dialog but with option of Input text box as bellow.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjsFWgemWXYb2LFxa3kKg_m3_an2gk2g_h9dqZFboIXPs1cUHtI92_daXIuDMA4I8mLmAjFl64DsA2ivjVMhVQv0_XHkSDfoYnFOhCwPrYkCkkQxWvf-_JmidFm-xLb8xqopo-xskRRLnn/s1600/Prompt+webdriver.PNG

To Input value In that text box of prompt dialog, You can use bellow given syntax.

driver.switchTo().alert().sendKeys("Jhon");


36 : When I am running software web application's tests In Firefox Browser using selenium webdriver, It Is not showing me any bookmarks, addons, saved passwords etc. In that browser. Do you know why?
Answer : Yes. It Is because all those bookmarks, addons, passwords etc.. are saved In your regular browser's profile folder so when you launch browser manually, It will use existing profile settings so
It will show you all those stuffs. But when you run your software web application's tests In selenium webdriver, It Is opening new browser Instance with blank/new profile. So It will not show you bookmarks and all those things In that browser Instance.

You can create custom firefox profile and then you can use It In selenium webdriver test. In your custom profile, you can set all required bookmarks, addons etc.. VIEW THIS EXAMPLE to know how to set custom profile of firefox browser.


37 : Arrange bellow given drivers In fastest to slowest sequence?
Firefox Driver, HtmlUnit Driver, Internet Explorer Driver.
Answer : HTMLUnit Driver Is faster than all other drivers because It Is not using any UI to execute test cases of software web application. Internet Explorer driver Is slower than Firefox and HtmlUnit driver. So, Fastest to slowest driver sequence Is as bellow.
1.     HtmlUnit Driver
2.     Firefox Driver
3.     Internet Explorer Driver
38 : What Is Ajax?
Answer : Asynchronous JavaScript and XML Is full form of AJAX which Is used for creating dynamic web pages very fast for software web applications. Using ajax, We can update page behind the scene by exchanging small amounts of data with server asynchronously. That means, Using ajax we can update page data Without reloading page.


39 : How to handle Ajax In selenium WebDriver?
Answer : Generally we are using Implicit wait In selenium WebDriver software automation tests to wait for some element to be present on page. But Ajax call can not be handled using only Implicit wait In your test because page not get reloaded when ajax call sent and received from server and we can not assume how much time It will take to receive ajax call from server.

To handle ajax call In selenium WebDriver software automation tests, We needs to use webdriver's FluentWait method or Explicit Waits which can wait for specific amount of time with specific condition. You can get different Explicit Waits examples links on THIS PAGE.


40 : On Google search page, I wants to search for some words without clicking on Google Search button. Is It possible In WebDriver? How?
Answer : Yes we can do It using WebDriver sendKeys method where we do not need to use Google Search button. Syntax Is as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("Search Syntax",Keys.ENTER);

In above syntax, //input[@id='gbqfq'] Is xPath of Google search text field. First It will enter "Search Syntax" text In text box and then It will press Enter key on same text box to search for words on Google.


selenium interview question 7

23 : Do you need Selenium Server to run your tests In selenium WebDriver?
Answer : It depends. If you are using only selenium webdriver API to run your tests and you are running your all your tests on same machine then you do not need selenium server because In this case, webdriver can directly Interact with browser using browser's native support.

You need selenium server with webdriver when you have to perform bellow given operations with selenium webdriver.
  • When you are using remote or virtual machine to run webdriver tests for software web application and that machine have specific browser version that is not on your current machine.
  • When you are using selenium-grid to distribute your webdriver's test execution on different remote or virtual machines.
24 : Bellow given syntax will work to navigate to specified URL In WebDriver? Why?

driver.get("www.google.com");
Answer : No. It will not work and show you an exception like : "Exception in thread "main" org.openqa.selenium.WebDriverException: f.QueryInterface is not a function" when you run your test.

You need to provide
 http:// protocol with URL In driver.get method as bellow.

driver.get("http://www.google.com");
Now It will work.

25 : Tell me a reason behind bellow given WebDriver exception and how will you resolve It?
"Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element"
Answer : You will get this exception when WebDriver Is not able to locate element on the page of software web application using whatever locator you have used In your test. To resolved this Issue, I will check bellow given things.
  • First of all I will check that I have placed Implicit wait code In my test or not. If you have not placed Implicit timeout In your test and any element Is taking some time to appear on page then you can get this exception. So I will add bellow given line at beginning of my test case code to wait for 15 seconds for element to be present on page. In 70% cases, this step will resolved Issue. View Practical Example Of Implicit Wait.
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

  • Another reason behind this Issue Is element's ID Is generated dynamically every time when reloading the page. If I have used element's ID as an element locator or used It In xpath to locate the element then I need to verify that ID of element remains same every time or It Is changing? If It Is changing every time then I have to use alternative element locating method. In 20% cases, This step will resolve your Issue.
  • If Implicit wait Is already added and element locator Is fine then you need to verify that how much time It(element) Is taking to appear on page. If It Is taking more than 15 seconds then you have to put explicit wait condition with 20 or more seconds wait period as bellow. In 5 to 10% cases, This step will resolve your Issue. View Example.
WebDriverWait wait = new WebDriverWait(driver, 25);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")));


26 : Can we automate desktop software application's testing using selenium WebDriver?
Answer : No. This Is the biggest disadvantage of selenium WebDriver API. We can automate only web and mobile software application's testing using selenium WebDriver.
27 : Can you tell me the alternative driver.get() method to open URL In browser?
Answer : We can use anyone from bellow given two methods to open URL In web browser In selenium webdriver software testing tool.
1.   driver.get()
2.   driver.navigate().to()
28 : Can you tell me a difference between driver.get() and driver.navigate() methods?
Answer : Main and mostly used functions of both methods are as bellow.

driver.get()
  • driver.get() method Is generally used for Open URL of software web application.
  • It will wait till the whole page gets loaded.
driver.navigate()
  • driver.navigate() method Is generally used for navigate to URL of software web application, navigate back, navigate forward, refresh the page.
  • It will just navigate to the page but wait not wait till the whole page gets loaded.
29 : WebDriver has built In Object Repository. Correct me If I am wrong.
Answer : No. WebDriver do not have any built In object repository till now. But yes, I am using java .properties file In my framework to store all required element objects In my tests. View Example.
30 : Can you tell me syntax to set browser window size to 800(Width) X 600(Height)?
Answer : We can set browser window size using setSize method of selenium webdriver software testing tool. To set size at 800 X 600, Use bellow given syntax In your test case.


driver.manage().window().setSize(new Dimension(500,500));


Handling Dynamic Elements in Selenium WebDriver

                       Handling Dynamic Elements in Selenium WebDriver Dynamic elements are those elements which have identifiers that a...