WebElement Interface

 1. What is meant by WebElement?

  1. WebElement is an Interface provided by Selenium to identify HTML elements in the web page. 
  2. It provides methods to interact with web elements such as clicking, entering text etc..

2. How do you verify the element is present?

driver.findElement(By.tagName(‘row’)).isPresent();

3. What is an element?

An element is an object represented in a web page.

4. Element Locating Mechanism

  1. These are static methods
  2. By is an Abstract class
  3. All the methods argument type is String
1.By.id();
2.By.name();
3.By.className();
4.By.tagName();
5.By.linkText();
6.By.partialLinkText();
7.By.xpath();
8.By.cssSelector();

5. Can you explain how you can handle colours in a web driver?

  1. We can use the command getCSSValue(arg0) to fetch the colours by sending the colour as the argument
  2. It is a method in WebElement Interface
  3. These are the properties: background, font, border, border-top, margin, margin-top, padding, padding-top, list-style, outline, pause, cue
driver.findElement(By.id('id')).getCssValue(String css property)
//Get the value of a given CSS property

6. What are the methods of web elements?

  1. click()
  2. clear()
  3. sendKeys()
  4. getCssValue() : To get the colour/size/font of the particular
  5. getText()
  6. getAttribute()
  7. isDisplayed()
  8. isSelected()
  9. getTagName() : To get the tagname of particular webelement
  10. getSize()
  11. getLocation():To get the X-axis and Y-axis location particular web element
  12. isEnabled()
  13. submit(): To click on an element only if the type of the element is submitted Ex: <input type=” submit” id=”s” value=”Submit”>

7. John is not sure if the warning text label is displayed on the web page of a blog. How will you help him using Selenium?

We can use the method isDisplayed() to confirm the presence of the element on the screen.

Boolean buttonPresence = driver.findElement(by.id("sample").isDisplayed();

8. What is the difference between getText() and getAttribute() methods?

  1. getText(): it returns the text of the selected element.
driver.findElement(“elementLocator”).getText();

  2. getAttribute(): it returns the value of the attribute in a given element.

driver.findElement(By.className("row"))getAttribute("value" or "name", "id" etc…)

9. How to verify that the element is displayed on the web page?

Using isDisplayed() method. It returns a true or false Boolean value.

driver.findElement(By.id(‘row’)).isDisplayed();

10. How to check web element is enabled for interaction?

driver.findElement(element).isEnabled();

It returns a Boolean value true or false.

11. How to locate a link using its text?

  1. Use linkText() or partialLinkText()
driver.findElement(By.linkText(“hey”));

12. How to extract the value of the tooltip text?

  1. The web page uses the ‘title’ attribute to keep the tooltip text
  2. We can fetch the value from the title attribute using the below way
String tooltip = driver.findElement(By.id('row')).getAttribute('title')

13. How to select a radio button using a selenium web driver?

driver.findElement(radioBtn).click();

14. How to check on the checkbox?

driver.findElement(By.id(“row”)).click();

15. How to submit a form using selenium?

  1. Use the submit() method or click on the submit button element.


No comments:

Post a Comment

Cucumber

What is Cucumber? Definition : Cucumber is an open-source tool that supports BDD . Purpose : Bridges the communication gap between business ...