Selenium Java Interview Questions And Answers – Part 13

Selenium Java Interview Questions And Answers – Part 13

Selenium Java Interview Questions and Answers Part-13

1) Explain how will automate drop down list ? How will you get size ? and text present in it?

We can use the Select class and methods to automate drop down list. We will get the size of the
items by using getOptions() method. We can iterate through each item and get its text by using getText() method.

WebElement ddElement = driver.findElement(By.id("country"));
Select select = new Select(ddElement);
List<WebElement> items = select.getOptions();
for(WebElement element: items){


2) Give me another way u can send values other than sendkeys?

We can use JavaScript Executor to send values.

JavascriptExecutor JS = (JavascriptExecutor)webdriver;


3) What is regular expression? Where will we use it?

A regular expression is a sequence of characters that define a search pattern. Usually such patterns are used by string searching algorithms for “find” or “find and replace” operations on strings, or for input validation.

They can be used for:
– extracting text from the value of a webelement
– validating if a value matches a specific pattern
– validating if a url matches a pattern

4) How do you start selenium server?

We can start the selenium server using the below command:

java -jar selenium-server-standalone-3.11.0.jar


5) How do you download and use selenium?

We can download Selenium by using Maven dependencies and import the Selenium packages in our classes.

6) How do you differentiate check box if more than one check box is existed in your application?

We can first get the list of all check-boxes and then use index to perform operation on a particular check-box.

List<WebElement> elements = driver.findElement(By.id("check"));


7) How to get the href of a link?

We can use the getAttribute method to get href of a link.

String str = driver.findElement(By.id("Submit")).getAttribute("href");


8) How to get the source of image?

We can use the getAttribute method to get source of image.

String source = driver.findElement(By.id("img")).getAttribute("src"));


9) Write a program to count the number of links in a page?

List<WebElement> allLinks = driver.findElement(By.tagName("a"));
int count = allLinks.size();


10) How to check all check-boxes in a page?

List<WebElement> checkboxes = driver.findElement(By.xpath("//input[@type='checkbox']"));
for(WebElement element: checkboxes){


11) What is the output of the below code? driver.findElements(By.tagName(“img”));?

It will return all the elements from the page which have tagname as img.

12) How do you handle JavaScript alert/confirmation popup?

Using Alert class and its different methods.

Alert alert = driver.switchTo().alert();
//Click on OK button
//Click on close button
//Get text present on Alert


13) How do you launch IE?

System.setProperty("webdriver.ie.driver","//path of IE Driver");
WebDriver driver = new InternetExplorerDriver();


14) How do you launch Chrome browser?

System.setProperty("webdriver.chrome.driver","//path of Chrome Driver");
WebDriver driver = new ChromeDriver();


15) How do you click on a menu item in a drop down menu?

WebElement element = driver.findElement(By.id("menu"));
Select dropdown = new Select(element);


16) How do you work with page onload authentication popup?

driver.get("http://UserName:[email protected]");


17) How do you handle untrusted certificates?

DesiredCapabilities certificate = DesiredCapabilities.chrome();
certificate.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (certificate);


18) How to verify that the font-size of a text is 12px?



19) How to get typed text from a textbox?

String text = driver.findElement(By.id("textbox")).getAttribute("value");


20) What is the use of following-sibling ?

It selects all the siblings after the current node.



21) What is StaleElementException? When does it occur? How do you handle it?

This Exception occurs when driver is trying to perform action on the element which is no longer exists or not valid. Try to get around this by first using an explicit wait on the element to ensure the ajax call is complete, then get a reference to the element again.

By byPageLoc = By.id("element");


22) How to get the number of frames on a page?

List<WebElement> frames = driver.findElement("By.id("frame-id"));
int count = frames.getSize();


23) How to verify that an element is not present on a page?

boolean isElementDisplayed = driver.findElement(By.id("login")).isDisplayed();
System.out.println("Element is not present");


24) What is the use of getPageSource()?

It returns the complete html source code of the page.

25) What is the difference between dragAndDrop() and dragAndDropBy()?

Difference between dragAndDrop and dragAndDropBy is that, dragAndDropBy moves the source element not to the target element but to the offsets.

Next Steps:

> More interview questions and answers on Selenium Java, continue to the next post (Click on Next Post link below)

> Check complete Selenium Java interview questions and answers here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Bijan Patel

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.


Comments (0)

Leave a Reply

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

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp