Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

1.

Different types of exceptions thrown in Selenium

Answer:
1. NoSuchElementException
2. ElementNotVisibleException
3. InvalidSelectorException
4. ElementClickInterceptedException
5. StaleElementReferenceException
6. UnhandledAlertException
7. NoAlertPresentException
8. NoSuchFrameException
9. NoSuchWindowException
10. TimeoutException

2. What are the different C# Unit testing frameworks are available?

Answer:
MSTest, NUnit, xUnit.Net

3. In NUnit test how we can be logically divided the test?

Answer:
"OneTimeSetUp", "SetUp", "TeadDown", "OneTimeTeadDown"
and "Test"
4. What output will be generated for the below code?

using NUnit.Framework;

namespace SeleniumLearning
{
public class Tests
{
[SetUp]
public void Setup()
{
TestContext.Progress.WriteLine("This is Setup Method");
}

[Test]
public void Test1()
{
TestContext.Progress.WriteLine("This is Test1 Method");
}

[Test]
public void Test2()
{
TestContext.Progress..WriteLine("This is Test2 Method");
}

[TearDown]
public void AfterTest()
{
TestContext.Progress..WriteLine("This is AfterTest
Method");
}
}

Answer:
This is Setup Method
This is Test1 Method
This is AfterTest Method
This is Setup Method
This is Test2 Method
This is AfterTest Method

5. How to Log in "NUnit" test?


Answer:
TestContext.Progress.WriteLine("This is test log");
TestContext.WriteLine("This is test Log");

6. How the "ChromeDriver" object can be created?

Answer:
IWebDriver driver = new ChromeDriver();

7. Can Selenium perform actions directly on drivers such as


"FirefoxDriver", "EdgeDriver" and "ChromeDriver"?

Answer:
No

8. What does the WebDriverManager do?

Answer:
Downloads driver.exe, takes care of driver.exe location and takes
care of Browser version and it compatible driver.exe

9. What are the Locators list supported by Selenium?

Answer:
ID, Name, ClassName, Tagname, LinkText, PartialLinkText, Xpath,
CssSelector

10. For an object the attributes(ID, Name, ClassName, LinkText) are not
defined, can Xpath and CssSelector be used to query and find the
corresponding object?

Answer:
Both will find the objects

11. While using "Thread.Sleep(3000);" is it necessary to import the


"System.Threading" namespace?

Answer:
It has to imported or else compile time error will be displayed

12. Whether the below syntax of XPath and CssSelector are correct?

XPath : //label[@class="Rahul"]/span[2]/input
CssSelector: .Rahul span:nth-child(2) input

Answer:
Yes, both will identify the object
13. Implicit Wait is applied to all test steps globally?

Answer:
It is applied to all the test steps in the test script

14. For using WebDriverWait which package and namespace should be


imported?

Answer:
Selenium.WebDriver package -OpenQA.Selenium namespace
Selenium.Support package -OpenQA.Selenium.Support.UI
namespace

15. Confirm whether the below code would wait until the WebElement is
visible?

WebDriverWait wait = new


WebDriverWait(driver,TimeSpan.FromSeconds(8));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVi
sible(By.CssSelector("#alert-danger")));

Answer:
Yes, the code will wait until 8 seconds to the object to be visible
or else it will fail
16. While using ArrayList should the namespace
"System.Collections.Generic" be imported?

Answer:
It has to imported or else compile time error will be displayed

17. Which method is used to validate whether Radio Button option is


Enabled?

Answer:
.Selected();
.Enabled();

18. For performing the Positive & Negative (such as Confirm, OK, Cancel
and NO) operations in alerts, confirm which methods can be used?

Answer:
driver.SwitchTo().Alert().Accept();
driver.SwitchTo().Alert().Dismiss();

19. User Interactions (such as Mouse Hover, Right click, Double click and
Drag & Drop) are handled by which class?

Answer:
User interactions with the User interface are handled by Actions
class

20. Driver can move control to Frame using which statements?

Answer:
driver.SwitchTo().Frame("ID");
driver.SwitchTo().Frame(Index);
driver.SwitchTo().Frame("Name");

21. If the element is present inside the frame and if driver is not
switched to frame, what will be execution result?

Answer:
Run Time Error will be displayed, such as
"NoSuchElementException"

22. What is the “CssSelector” for identifying the object using tagname?

Answer:
By.CssSelector("By.CssSelector("h1"))"))
23. Is the Browser "New Tab", will be treated by Selenium as Child
Windows?

Answer:
Yes, "New Tab" is browser setting of new the window

24. What does the "String.Trim();" do?

Answer:
Removes all leading and trailing white-space characters from the
current string

25. The "driver.CurrentWindowHandle;" will return what?

Answer:
It will return the "ActiveWindowName" As String

26. Command used to switch to child window?

Answer:
driver.SwitchTo().Window(windowName);

27. Write a program to split the word "Rahul Shetty Academy" into 3
separate words and print the same?
Answer:
String a1 = "Rahul Shetty Academy";
var a = a1.Split(" ");

TestContext.Progress.WriteLine(a[0]);
TestContext.Progress.WriteLine(a[1]);
TestContext.Progress.WriteLine(a[2]);

28. Write a program to sort the array list?

Answer:
ArrayList name = new ArrayList();
name.Add("Rahul Shetty");
name.Add("James");
name.Add("Adam");
name.Add("Zuhor");
name.Sort();

29. Write the command to retrieve the string from alert message?
Answer:
string alertMSG = driver.SwitchTo().Alert().Text;
30. Write the command to retrieve the data from auto suggestive box?

Answer:
string autoSuggestiveValue =
driver.FindElement(By.CssSelector("#autocomplete")).GetAttribute("valu
e");
string autoSuggestiveValue =
driver.FindElement(By.CssSelector("#autocomplete")).Text;

You might also like