1. What is meant by WebElement?
- WebElement is an Interface provided by Selenium to identify HTML elements in the web page.
- 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
- These are static methods
- By is an Abstract class
- 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?
- We can use the command getCSSValue(arg0) to fetch the colours by sending the colour as the argument
- It is a method in WebElement Interface
- 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?
- click()
- clear()
- sendKeys()
- getCssValue() : To get the colour/size/font of the particular
- getText()
- getAttribute()
- isDisplayed()
- isSelected()
- getTagName() : To get the tagname of particular webelement
- getSize()
- getLocation():To get the X-axis and Y-axis location particular web element
- isEnabled()
- 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?
- 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?
- Use linkText() or partialLinkText()
driver.findElement(By.linkText(“hey”));
12. How to extract the value of the tooltip text?
- The web page uses the ‘title’ attribute to keep the tooltip text
- 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?
- Use the submit() method or click on the submit button element.
No comments:
Post a Comment