Selenium interview questions - Part 4

31) How to check if element is Enabled Or Disabled
boolean fname = driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();

32) Which method is used to submit form?
submit() method is used to submit the form.
driver.findElement(By.xpath("//input[@name='Company']")).submit();

33) How to read font properties in Selenium WebDriver?
WebElement text = driver.findElement(By.id("fname"));
String fontColor = text.getCssValue("color");
String fontFamily = text.getCssValue("font-family");
String fonttxtAlign = text.getCssValue("text-align");

34) How to get X Y Coordinates Of Element?
WebElement Image = driver.findElement(By.id("profilepicture"));
Point point = Image.getLocation();
int xcordinate = point.getX();
int ycordinate = point.getY();

35) How to get height and width Of WebElement?
WebElement Image = driver.findElement(By.id("profilepicture"));
int ImageWidth = Image.getSize().getWidth();
int ImageHeight = Image.getSize().getHeight();

36) How we can wait for page to load/ready?
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("return document.readyState").toString().equals("complete");

37) How to perform drag and drop operation in Selenium WebDriver?
Drag and drop can be performed by Selenium WebDriver's Advanced User Interactions API. The syntax is as follows.
Actions act = new Actions(driver);
act.dragAndDrop(From, To).build().perform();

38) What are the different technical challenges you faced with Selenium WebDriver software test automation?
  • Sometimes, Some elements like text box, buttons etc. are taking more time to appear on page. In such situation, if we have used only Implicit wait then my test case can run fine on first run but it may fail to find element on second run. So we need provide special treatment for such elements so that webdriver script wait for element to be present or get enabled on page of software web application during test execution. So solution to this problem, We used Explicit wait to handle this situation. 
  • Dynamically changing ID to locate element was one of the challenge that I faced in test automation. If element's ID Is changing every time when you reload the software web application page and you have to use that ID in XPath to locate element then you have to use functions like starts-with(@id,'post-body-') or contains(@id,'post-body-') 
  • Clicking on sub menus which are getting rendered on mouse hover of main menu was one of the challenge I faced. We need to use webdriver's Actions class to perform mouse hover operation. 
  • While executing test script in Chrome and Firefox, it was working fine however while running script on IE it was getting failed. This issue can arise due to the unsupported XPath In IE browser. In this case, You need to use other element locating methods (ID, Name, CSSSelector etc.) to locate element.
  • If you have to execute your test cases In multiple browsers then one test case can run successfully In Firefox browser but same test case may fail In IE browser due to the timing related Issues (nosuchelement exception) because test execution In Firefox browser Is faster than IE browser. You can resolve this Issue by Increasing Implicit wait time when you run your test In IE browser.

39) How do you close current and all opened WebDriver Instances?
To close current WebDriver Instance, we can use Close() method as follow.
driver.close();

If there are opened multiple WebDriver instances and wants to close all of them then we can use webdriver's quit() method as bellow.
driver.quit();

40) How to generate alert by executing java script in WebDriver Script?
We can execute java script in test execution. To generate alert, You can write following code in your script.
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Javascript Executed.');");



<-- Previous || Next -->

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete