Selenium Interview QA-RM01
Selenium Interview QA-RM01
command?
If you need to type keyboard key values into a text field of the web
application, "type" command will be used. Another reason for its usage is
selecting values of the combo box. "typeAndWait" command is used
when your typing is completed and software web page start reloading.
copy
1. WebElement element =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”))
13) How can we find the value of different attributes like name,
class, value of an element?
copy
1. getAttribute("{attributeName}") //method is used find the value of
different attributes of an element
copy
1. import org.testng.annotations.Test;
2. public class testNGPriorityExample {
3. @Test
4. public void registerAccount() {
5. System.out.println("Create an account");
6. }
7. @Test(priority=2)
8. public void sendEmail() {
9. System.out.println("Confirm your account");
10. }
11. @Test(priority=1)
12. public void login() {
13. System.out.println("Execute login after confirmation");
14. }
15. }
27) Explain how you can find broken images in a page using
Selenium Web driver?
You have to follow the next steps to find broken images in a page using
Selenium Web driver:
• get XPath and get the all links on the page using the tag name • click
on every link on the page • look for 404/500 in the target page title 55)
Can captcha and bar code reader be automated by using Selenium?
Neither captcha, no bar code reader can be automated by using
Selenium.
28) How to verify tooltip text using Selenium? The tooltip text in
Selenium could be verified by fetching the value of 'title'
• attribute. An example:
• copy 1. String toolTipText = element.getAttribute("title");
29) How to locate a link using its text in Selenium?
linkText() and partialLinkText() are used for link location. The
examples:
copy 1. WebElement link1 =
driver.findElement(By.linkText(“some_link_test”)); 2. WebElement link2 =
driver.findElement(By.partialLinkText(“some_link_part_text”));
30) Can we find all links on a web page? As all links are of anchor tag
'a', so we can find all of them on a web page by locating elements of
tagName ‘a’: copy 1. List links = driver.findElements(By.tagName("a"));
31) How can we capture screenshots in Selenium? We can take the
screenshots in selenium by using getScreenshotAs method of
TakesScreenshot interface: copy 1. File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 2.
FileUtils.copyFile(scrFile, new File("C:\\screenshot1.jpg")); 60) Explain
how colors could be handled in Selenium WebDriver? To handle
colors could be handled in Selenium WebDriver by using Use
getCssValue(arg0) function to get the colors by sending ‘color’ string as
an argument. 61) How many exceptions do you know in Selenium
WebDriver? There are 5 different exceptions Selenium WebDriver: •
NoAlertPresentException,
• NoSuchElementException
• NoSuchWindowException
• TimeoutException
• WebDriverException
32) What is selenium grid?
Example:
copy
1. keyPress(KeyEvent.VK_DOWN)
• keyRelease(): method with release down arrow key of Keyboard:
Example:
copy
1. robot.keyRelease(KeyEvent.VK_DOWN)
• mouseRelease() method will release the right click of your mouse
Example:
copy
1. mouseRelease(InputEvent.BUTTON3_DOWN_MASK)
• mouseMove() method will move mouse pointer to the specified
X and Y coordinates.
Example:
copy
1. robot.mouseMove(point.getX(), point.getY())
• mousePress() method will press the right click of your mouse.
Example :
copy
1. robot.mousePress(InputEvent.BUTTON3_DOWN_MASK)
42) How to login into any site if it’s showing any authentication
pop-up for username and password?
You should pass the username and password with URL:
https://username:password@url
https://creds:[email protected]
45) Explain how you can use recovery scenario with Selenium?
You can use recovery scenario in accordance with the programming
language.
If it is Java then you can use exception handling to overcome same.
copy
1. driver.switchTo().alert().dismiss();
• void accept() is used to click on the 'OK' button of the alert.
copy
1. driver.switchTo().alert().accept();
• String getText() is used to capture the alert message.
copy
1. driver.switchTo().alert().getText();
• void sendKeys(String stringToSend) is used to send some data to
alert box.
copy
1. driver.switchTo().alert().sendKeys("Text");
55) How can you create HTML test report from your test script?
There are three ways of HTML test report creation:
• using inbuilt default.html to get the HTML report in TestNG
• with the ANT help in JUnit
• using XSL jar for converting XML content to HTML in own customized
reports
57) Explain how can you debug the tests in Selenium IDE?
The tests could be debugged in such way:
• insert a break point from the location from where you want to execute
test step by step
• run the test case
• test case execution will be paused at the given break point
• click on the blue button to continue with the next statement
• to continue executing all the commands at a time click on the “Run”
button
63) How can we make one test method dependent on other using
TestNG?
We can make one test method run only after successful execution of
dependent test method by using dependsOnMethods parameter inside
@Test annotation in TestNG: @Test(dependsOnMethods = { "preTests" })
64) How could you explain the main difference between WebDriver
and RC?
Selenium WebDriver drives the browser using built-in support. RC injects
JavaScript function into browsers when the page is loaded.
74) How can you run Selenium Server other than the default port
4444?
Selenium server could be run on java-jar selenium-server.jar-port other
than its default port.
75) Explain how you can capture server side log Selenium Server?
To capture server side log in Selenium Server, you can use command:
java –jar .jar –log selenium.log
77) Explain how can you insert a start point in Selenium IDE?
Selenium IDE can be set in two ways:
• in Selenium IDE right click on the command and the select “Set / Clear
Start Point”
• press “S” key on the keyboard and select the command in Selenium IDE