Selenium Interview Questons
Selenium Interview Questons
1. POM-Page Factory
@FindBy(name="txtUserID")
WebElement txtUserID
PageFactory.initElements(driver, this)
@FindAll({@FindBy(how=How.ID, using=”username”),
@FindBy(className=”username-field”)})
private WebElement user_name;
*You can also use this to group different FindBy into a WebElement list
@FindAll({@FindBy(xpath = “yourfirstxpath”),@FindBy(xpath =
“yoursecondxpath”),@FindBy(xpath = “yourThirddxpath”)})
public List<WebElement> resultElements;
HashMap-
A HashMap contains values based on the key. It implements the Map interface and
extends AbstractMap class.
It contains only unique elements.
It may have one null key and multiple null values.
It maintains no order.
it is not synchronized
Iterator we use for iteration
Methods- put- with key and value
remove- by passing key
HashTable- Same as HashMap but this is Synchronized. So hashtable is better for NON
thread Applications and HashTable does NOT allow null kays values. Enumerator we use
for iteration
9. Synch ways
1. Unconditional
2. Conditional Synchronization
3. PageLoadTimeout
4. Thread.Sleep
[AKSHAY] - As per my understanding Synchronization is of 2 types, Implicit (Conditional)
and Explicit (Unconditional),
Implicit type -- Wait the application unless and until certain period of time in order to see a
condition set’s True.
E.g. driver.manage().timeouts().implicitlyWait(2, TimeUnit.Minutes)
So the above instruction will wait for 2 Min, or less unless a particular element is
visible/available.
The 3rd point mentioned above Page Load Timeout is also a part of Implicit wait that wait’s
for the webpage to be loaded completely. Majorly used where the connectivity with the
application is slow or if there is any performance issue with the application.
Explicit type - Wait for a desired set of period/time before doing any other action/operation.
E.g. Thread.sleep(5000);
So above instruction will wait for 5 sec irrespective of whether the element is
visible/available or not.
Using JavaScriptExecutor
Using Robot Class
15. Screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
23. HTMLUnitDriver- HTML unit driver is the most light weight and fastest implementation
headless browser for of WebDriver.It is known as Headless Browser Driver.It is same as
Chrome, IE, or FireFox driver, but it does not have GUI so one cannot see the test
execution on screen.
[AKSHAY] - Use of Headless browser is mostly used to do Performance Testing, Running
automated tests for JavaScript libraries, where we don’t need to see or view any
screenshots for any pass or fail criteria.
Another example of Headless Browser is PhantomJS, [RAM]TrifleJS, Splash which are also
used in Selenium.
24. Firefox Preference- We can take help from about:config by entering FF browser
Set yahoo.com as startup page in FF
FirefoxProfile ffprofile= new FirefoxProfile();
profile.setPreference("browser.startup.homepage","http://www.yahoo.com");
driver = new FirefoxDriver(ffprofile);// We can use above profile by passing as a
parameter
28. Asserts
Assert.assertTrue() & Assert.assertFalse()
Assert.assertEquals()
assertEqualsNoOrder
assertNotNull
assertNotSame
29. Passing xls data to DataProvider- By using FileInputSTream and iterating through
every cell.
30. How to find element which is NOt visible in DOM but its visible in browser?
isDisplayed can be used to test if an element is visible right now, not if it exists in the dom
31. Explicitwait-
Explicit waits are done using the WebDriverWait and ExpectedCondition classes.
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element =
wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
ExpectedConditions- isEnabled, isDisplayed,isSelected
35. RemoteDriver
String hubURL = "http://myip:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
WebDriver driver = new RemoteWebDriver(new URL(hubURL), capability);
driver.get("http://www.google.com");
Disadvantages
You cannot throw Checked Exceptions.
You cannot use this keyword since there is no instance.
You shouldn’t try to access super since there is no such a thing for static blocks.
You should not return anything from this block.
47. getLocation Command- This method locate the location of the element on the page.
This accepts nothing as a parameter but returns the Point object.
50. private access modifier- The private access modifier is accessible only within class.
default access modifier - If you don't use any modifier, it is treated as default bydefault.
The default modifier is accessible only within package.
protected access modifier - The protected access modifier is accessible within package
and outside the package but through inheritance only.The protected access modifier
can be applied on the data member, method and constructor. It can't be applied on the
class.
public access modifier - The public access modifier is accessible everywhere. It has the
widest scope among all other modifiers.
61. Exract xpath of table cell/ Dynamic XPath- Done- Refer video again if need
List<WebElement> td_collection=trElement.findElements(By.xpath("td"));
System.out.println("NUMBER OF COLUMNS="+td_collection.size());
66. What are the test cases we cant automate by using Selenium?
Captcha
Bar code reader can't be tested.
76. How to handle exception in testNG without using try catch block?
77..disadvantages of static block in java?
TestNG provides an option of tracing the exception handling of code. You
can test whether a code throws a desired exception or not. Here the
expectedExceptionsparameter is used along with the @Test annotation.
Eg. @Test(expectedExceptions = ArithmeticException.class)
78. What are the available Access modifiers in java?
79. Maven goals and lifecycle?
80. What are the methods are available in POI?
81. whats java serialization?
--------L&T questions-----
Java programmed--