Selenium Qa

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

47) List out different types of locators?

Different types of locators are

By.id()
By.name()
By.tagName()
By.className()
By.linkText()
By.partialLinkText()
By.xpath
By.cssSelector()

35. When you use these locators ID, Name, XPath, Or CSS Selector?
ID & Name locators will be used when there are unique identifiers & unique names
available on the web page.
CSS Selector can be used for performance and when ID & Name locators are not
unique.
XPath is used when there is no preferred locators.

16. How to mouse hover over a web element?


Actions class utility is used to hover over a web element in Selenium WebDriver

Instantiate Actions class.

Actions action = new Actions(driver);

In this scenario, we hover over search box of a website

actions.moveToElement(driver.findElement(By.id("id of the
searchbox"))).perform();

----------------------------------------------------

40) Mention 5 different exceptions you had in Selenium web driver?


The 5 different exceptions you had in Selenium web drivers are

WebDriverException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
TimeoutException

20. How does Selenium handle Windows-based pop-ups?


Selenium was designed to handle web applications. Windows-based features are not
natively supported by Selenium. However, third-party tools like AutoIT, Robot, etc
can be integrated with Selenium to handle pop-ups and other Windows-based features.

------------------------------------------------------

21. How to take screenshots in WebDriver?


TakeScreenshot interface can be used to take screenshots in WebDriver.
getScreenshotAs() method can be used to save the screenshot

File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

------------------------------------------------------

25. How to upload a file in Selenium WebDriver?


You can achieve this by using sendkeys() or Robot class method. Locate the text box
and set the file path using sendkeys() and click on submit button

Locate the browse button

WebElement browse =driver.findElement(By.id("uploadfile"));

Pass the path of the file to be uploaded using sendKeys method

browse.sendKeys("D:\\SeleniumInterview\\UploadFile.txt");

----------------------------------------
38. Explain the difference between assert and verify commands.
The assert command is used to check if the given condition is true or not. If the
condition is true, then the execution of the program will continue. If the
condition is false, then the execution of the program will stop.

The verify command is used to check if the given condition is true or not. If the
condition is true, then the execution of the program will continue. If the
condition is false, then the execution of the program will not stop, but an error
message will be displayed.

39. What do you mean by XPath?


XPath is a language for addressing parts of an XML document. XSLT and other XML-
related technologies use it to access data within XML documents. XPath can be used
to navigate through elements and attributes in an XML document. XPath is a major
element in the XSLT standard and is crucial for processing XML documents.

40. Explain XPath Absolute and XPath attributes.


XPath has two main types of expressions: absolute and relative. Absolute
expressions always start with a forward slash (/), which indicates the root element
of the document. Relative expressions do not start with a forward slash, and are
relative to the current context.

Attributes are another important part of XPath. Attributes are added to elements
and can contain valuable information about that element. In order to access an
attribute, you must use the at sign (@) followed by the attribute name.

41. What is the difference between "/" and "//" in XPath?


The difference between "/" and "//" in XPath is that "/" is used to select an
element based on its absolute location, while "//" is used to select an element
based on its relative location.

For example, if you want to select the first <p> element on a page, you would use
"/p". If you want to select all <p> elements on a page, regardless of their
location, you would use "//p".

42. What are the different types of annotations which are used in Selenium?
Different types of annotations that are used in Selenium include:

@Test - This annotation is used to mark a method as a test method


@BeforeMethod - This annotation is used to execute a method before each test method
@AfterMethod - This annotation is used to execute a method after each test method
@BeforeClass - This annotation is used to execute a method before the first test
method
-----------------------------------------------------------------------------------
--
51. How do you perform drag and drop operations in WebDriver?
When using WebDriver, you can perform drag and drop operations using the Actions
class. This class has a number of methods that can be used to perform various
actions, such as clicking, dragging, and dropping. In order to use the Actions
class, you first need to instantiate it with a WebDriver instance:

Actions actions = new Actions(driver);

Once you have an Actions instance, you can use the dragAndDrop() method to perform
a drag and drop operation. This method takes two WebElements as arguments: the
element toDrag, and the element toDrop. For example, to drag an element with the id
"draggable" and drop it on an element with the id "droppable", you would do the
following:

WebElement draggable = driver.findElement(By.id("draggable"));

WebElement droppable = driver.findElement(By.id("droppable"));

actions.dragAndDrop(draggable, droppable).perform();

You can also use the clickAndHold() and release() methods to perform a drag and
drop operation. The clickAndHold() method takes a WebElement as an argument and
"grabs" it, while the release() method releases the element. For example:

actions.clickAndHold(draggable).release(droppable).perform();

You can also chain together multiple Actions methods to create more complex
interactions. For example, the following code will first move to the draggable
element, then click and hold it, move to the droppable element, and finally release
it:

actions.moveToElement(draggable).clickAndHold().moveToElement(droppable).release().
perform();

-----------------------------------------

--------------------------

-------------------

------------------------------------

You might also like