Selenium Interview Questions and Answers Set 4

31. How to get the number of frames on a page?

int numOfFrames = frameList.size (); 

32. How do you simulate scroll down action?

JavaScript Executor jsx = (JavaScript Executor) driver;
jsx.executeScript (“window.scrollBy (0, 4500)”, “”); //scroll down, value 4500 you can change as per your req
jsx.executeScript (“window.scrollBy (450,0)”, “”); //scroll up
public class Scroll Down {
public static void main (String[] args) throws Interrupted Exception {
WebDriver driver = new Firefox Driver ();
driver.manage ().timeouts ().implicitly Wait (10, TimeUnit.SECONDS);

33. What is the command line we have to write inside a .bat file to execute a selenium project when we are using TestNG?

Java cp bin; jars/* org.testng.TestNG testng.xml 

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

35. How to check if an element is visible on the web page?

Use is Displayed() method.The return type of the method is Boolean.So if it returns true then the element is visible else not visible.

driver.findElement (By.xpath (“xpath of element”)).is Displayed (); 

Weekend / Weekday Batch

36. How to check if a button is enabled on the page?

Use is Enabled () method. The return type of the method is Boolean. So if it returns true then the button is enabled else not enabled.

driver.findElement (By.xpath (“xpath of button”)).is Enabled (); 

37. How to check if a text is highlighted on the page ?

To identify weather color for a field is different or not,

String color = driver.findElement (By.xpath (“//a [text () =’Shop’]”)).getCssValue (“color”);
String backcolor = driver.findElement (By.xpath (“//a [text () =’Shop’]”)).getCssValue
System.out.println (color);
System.out.println (backcolor);

Here if both color and back color different then that me that element is in different colour. 

38. How to check the checkbox or radio button is selected?

Use isSelected () method to identify. The return type of the method is Boolean. So if it return true then button is selected else not enabled.
driver.findElement (By.xpath (“xpath of button”)).isSelected (); 

39. How to get the title of the page?

Use getTitle () method.
Syntax: driver.getTitle (); 

40. How does u get the width of the textbox?

driver.findElement (By.xpath (“xpath of textbox”)).getSize().getWidth ();
driver.findElement (By.xpath (“xpath of textbox”)).getSize().getHeight();