Selenium Interview Questions and Answers Set 5

41. How do u get the attribute of the web element?

driver.getElement (By.tagName (“img”)).getAttribute(“src”) will give you the src attribute of this tag.
Similarly, you can get the values of attributes such as title, alt etc.
Similarly you can get CSS properties of any tag by using getCssValue (“some property name”). 

42. How to check whether a text is underlined or not?

Identify by getCssValue (“borderbottom”) or sometime getCssValue (“text decoration”) method if the CssValue is „underline‟ for that WebElement or not.


This is for when moving cursor over element that is going to be underlined or not

public class UnderLine
public static void main (String [] args)
WebDriver driver = new Firefox Driver();
driver.manage ().timeouts ().implicitly Wait (10, TimeUnit.SECONDS);
driver.get (““);
StringcssValue=driver.findElement (By.xpath(“//a[text()=’Hindi’]”)).getCssValue(“textdecoration”);
System.out.println (“value”+cssValue);
Actions act = new Actions(driver);
act.moveToElement (driver.findElement (By.xpath (“//a[text()=’Hindi’]”))).perform();
String cssValue1=driver.findElement (By.xpath(“//a[text()=’Hindi’]”)).getCssValue(“textdecoration”);
System.out.println (“value over”+cssValue1);
driver.close ();

43. 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.

44. How to hover the mouse on an element?

Actions act = new Actions(Driver)
act.moveToElement (WebElement); //WebElement on which you want to move cursor 

45. What is the use of get Options () method?

get Options () is used to get the selected option from the dropdown list. 

Weekend / Weekday Batch

46. What is the use of deselect All () method?

It is used to deselect all the options which have been selected from the dropdown list. 

47. Is WebElement an interface or a class?

WebDriver is an Interface. 

48. Firefox Driver is class or an interface and from where is it inherited?

Firefox Driver is a class. It implements all the methods of WebDriver interface. 

49. What is the difference b/w close () and quit ()?

close()–it will close the browser where the control is.
quit () – it will close all the browsers opened by WebDriver. 

50. Can Selenium handle windows based pop up?

Selenium is an automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Selenium.