Selenium-FAQs TM PDF
Selenium-FAQs TM PDF
Selenium FAQs
3. What are different Xpath functions that you have used in your Project?
Relative Path
Contains
By Attribute name and value
Parent to Child and Vice Versa relationship
Following-sibling
Preceeding-sibling
And
10. What are the common exceptions you see in Selenium? How are those handled?
NoSuchElementException :FindBy method can’t find the element.
StaleElementReferenceException : This tells that element is no longer appearing on the DOM
page.
TimeoutException: This tells that the execution is failed because the command did not complete
in enough time.
ElementNotVisibleException: Thrown to indicate that although an element is present on the
DOM, it is not visible, and so is not able to be interacted with
ElementNotSelectableException: Thrown to indicate that may be the element is disabled, and
so is not able to select.
12. What are different wait mechanisms that can be used in scripting?
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebDriverWait
Thread.sleep(8000);
FluentWait
13. What are different pop-ups that you have handle in your projects?
JavaScript Pop Ups --- Alert alert = driver.switchTo().alert();
Browser Pop Ups --- Browser Profiles, Robot tool Kit, AutoIT
Native OS Pop Ups--- Browser Profiles, Robot tool Kit, AutoIT
15. How do you handle HTTP Proxy Authentication pop ups in browser?
Form authentications URL - http://UserName:[email protected]
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/events/Abstr
actWebDriverEventListener.html
If you have a need to find an element using a complex selector, I usually recommend using CSS
Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases,
without exhibiting the extreme performance penalty on IE that XPath can.
25. What is the difference between "GET" and "NAVIGATE" to open a web page in selenium web
driver?
navigate().to() and get() do exactly the same thing. One's just a lot easier to type than the other!
The navigate interface also has the ability to move backwards and forwards in your browser’s
history:
26. Please tell me the difference b/w implicitly Wait and Explicit wait.
Implicit Wait sets internally a timeout that will be used for all consecutive Web Element
searches. It will try lookup the element again and again for the specified amount of time before
throwing a NoSuchElementException if the element could not have been found. It does only this
and can't be forced into anything else - it waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more extendible
in the means that you can set it up to wait for any condition you might like. Usually, you can use
some of the prebuilt Expected Conditions to wait for elements to become clickable, visible,
invisible, etc., or just write your own condition that suits your needs.
www.testingmasters.com K.P.H.B MADHAPUR
+91 8790002007 +91 9100402385
Testing Masters Technologies
30. What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords, and
history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing versions etc.
http://code.google.com/p/selenium/wiki/FirefoxDriver
35. How to prepare Customized html Report using TestNG in hybrid framework.
Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XST reports from ANT,Selenium,
TestNG combination.
Using our own customized reports using XSL jar for converting XML content to HTML.
1.UsingsendKeys.Keys method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
2.Usingnavigate.refresh() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html");
driver.navigate().refresh();
driver.navigate().to(driver.getCurrentUrl());
5.UsingsendKeys() method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");
37. How to find broken images in a page using Selenium Web driver.
Get xpath and then using tag name; get all the links in the page
Use HttpURLConnector class and sent method GET
Get the response code for each link and verify if it is 404/500
42. How does u handle dynamic elements without using xpath (with example?)
By using classname or css.
45. How to handle alerts and confirmation boxes. Confirmation boxes and Alerts are handled in same
way in selenium.
var alert = driver.switchTo().alert();
alert.dismiss(); //Click Cancel or Close window operation
alert.accept(); //Click OK
Handle Confirmation boxes via JavaScript,
driver.executeScript("window.confirm = function(message){return true;};");
50. What is the default time for selenium Ide and webdriver?
Default timeout in selenium ide is 30 seconds.
For web driver go to below URL:
http://assertselenium.com/2013/01/29/webdriver-wait-commands/
54. "I want to find the location of ""b"" in the below code, how can I find out without using xpath,
name, id, csslocator, index.
a
b
c
driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
//div/button[contains(text(),'b']
55. Name 5 different exceptions you had in selenium web driver and mention what instance you got it
and how do you resolve it?
WebDriverException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
TimeoutException
1. WebDriverException
WebDriver Exception comes when we try to perform any action on the non-existing
driver.
WebDriver driver = new InternetExplorerDriver();
driver.get("http://google.com");
driver.close(); driver.quit();
2. NoAlertPresentException
When we try to perform an action i.e., either accept() or dismiss() which is not required
at a required place; gives us this exception.
try{
driver.switchTo().alert().accept();
}
catch (NoAlertPresentException E){
E.printStackTrace();
}
3. NoSuchWindowException
When we try to switch to an window which is not present gives us this exception:
WebDriver driver = new InternetExplorerDriver();
driver.get("http://google.com");
driver.switchTo().window("Yup_Fail");
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
window that is not present.
4. NoSuchFrameException
Similar to Window exception, Frame exception mainly comes during switching between
the frames.
WebDriver driver = new InternetExplorerDriver();
driver.get("http://google.com");
driver.switchTo().frame("F_fail");
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
frame that is not present.
5. NoSuchElementException
This exception is thrown when we WebDriver doesn’t find the web-element in the DOM.
WebDriver driver = new InternetExplorerDriver();
driver.get("http://google.com");
driver.findElement(By.name("fake")).click();
6. TimeoutException
Thrown when a command does not complete in enough time.
All the above exceptions were handled using try catch exceptions.
59. What is the difference between data driven and Keyword driven framework?
Data Driven Framework: Basically this type of Framework we read data from excel/some
external sheet.
Keyword Driven Framework: In the main script keyword drives which workflow/ testcases to
execute in generic term
60. What is the difference between Text area and Text field component?
Text Area: in generally like comment area where you are provide like 200 characters etc.
Text filed: where you type predefined text like country name etc.
http://beust.com/eclipse
62. How to count total no of hyperlinks in a page and click on the 5 th link if exist else display an error
message 5th link is not exist.
List<Webelemet>alllinks=driver,finElementsbytagname("a");
syso(alllinks.size());
63. There is an airline website from where you can choose source to destination place (e.g Bangalore
to Delhi) which gives you 10 different flight details like
A001N
A002N
A003N
A004N
A00234M
A00123M
…
From the above list include the flights which are ends with “M “character and exclude the flights which
are ends with “N” character.
Use xpath functions :- endWith() to find element ending with N
64. What is the difference between Web driver wait and fluent wait when we need to choose web
driver wait and fluent wait?
Fluent wait / driver wait belongs to explicit wait where it used to wait for Specific element
Fluent wait: suppress some expectation when element not found, Polling of web element we
can control which web driver wait doesn’t provide
68. Types of locator in selenium and which locator you used frequently?
ID, Name, Xpath and CSS Selector
69. How to click on an element which is not visible using selenium WebDriver?
We can use JavascriptExecutor to click