Selenium Interview Questions Part 3
Note : You can add questions and answer in comments section after the post. We will add them to the series if not duplicated.
21) While using click command can we use screen coordinate?
To click on specific part of element, we can use clickAT command. ClickAt command accepts element locator and x, y co-ordinates as arguments.
e.g. clickAt (locator, cordString)
22) What are the different types of Drivers available in WebDriver?
There are following drivers available in webdriver.
23) How to type in a textbox using Selenium?
We use ‘sendkeys’ method to enter the data into a textbox as shown below.
24) What is same origin policy? How you can avoid same origin policy?
The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site. As per the policy, any code loaded within the browser can only operate within that website’s domain.
To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL.
25) What is the difference between implicit wait and explicit wait?
Implicit wait: Implicit wait is used to provide a default timeout through out the script. Suppose, you have defined 20 seconds as implicit wait. Now, program control will wait for 20 seconds on each step and will move to next step only after 20 seconds has elapsed.
e.g. driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Explicit wait: Explicit wait is applied for a particular element. It will wait until a specified condition is meet or maximum time has elapsed , before moving to next step in the program.
For more detail, read this post..
26) How can we get a text of a web element?
We can use method ‘gettext()’ to the retrieve the text of a particular element.
String strText = driver.findElement(By.id(“myid”)).getText();
27) What kind of navigation commands are available in selenium?
There are following type of navigation command available in selenium.
navigate().back() – helps user to go back into the browser history made during selenium session.
navigate().forward() – helps user to go to next page into the browser history made during selenium session.
navigate().refresh() – helps user to refresh the current web page.
navigate().to() – helps user to launch a new web browser window and navigate to the specified URL.
28) How to get the current url of a browser?
You can use the below method to get the current url.
29) How to get the title of the browser opened by selenium?
You can use the below method to get the title.
30) How to select value in a dropdown?
We have to use select class provided by selenium webdriver. We can select the values in the following ways as mentioned below.
Select selectByValue = new Select(driver.findElement(By.id(“ID1”)));
Select selectByVisibleText = new Select (driver.findElement(By.id(“ID1”)));
Select selectByIndex = newSelect(driver.findElement(By.id(“ID1”)));