Professional Documents
Culture Documents
Selenium With C#
Selenium With C#
Answer:
1. NoSuchElementException
2. ElementNotVisibleException
3. InvalidSelectorException
4. ElementClickInterceptedException
5. StaleElementReferenceException
6. UnhandledAlertException
7. NoAlertPresentException
8. NoSuchFrameException
9. NoSuchWindowException
10. TimeoutException
Answer:
MSTest, NUnit, xUnit.Net
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
Answer:
IWebDriver driver = new ChromeDriver();
Answer:
No
Answer:
Downloads driver.exe, takes care of driver.exe location and takes
care of Browser version and it compatible driver.exe
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
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
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?
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
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
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
Answer:
Removes all leading and trailing white-space characters from the
current string
Answer:
It will return the "ActiveWindowName" As String
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]);
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;