Blog Detail

  • images_243.jpg

    Selenium Interview Questions For Experienced Part-3

    Question-1
    How to retrieve CSS properties of an element?

    getCssValue() method is used to retrieve CSS properties of any web element

    General Syntax:

    driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

    Example:

    driver.findElement(By.id(“email“)).getCssValue(“font-size”);

    Question-2
    Can Captcha be automated?

    No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to ensure that bots and automated programs don’t access sensitive information - which is why Selenium cannot automate it. The automation test engineer has to manually type the captcha while other fields can be filled automatically.

    Question-3
    How does Selenium handle Windows-based pop-ups?

    Selenium was designed to handle web applications. Windows-based features are not natively supported by Selenium. However, third-party tools like AutoIT, Robot, etc can be integrated with Selenium to handle pop-ups and other Windows-based features.

    Question-4
    Is there a way to type in a textbox without using sendKeys()?


    Yes! Text can be entered into a textbox using JavaScriptExecutor

    JavascriptExecutor jse = (JavascriptExecutor) driver;

    jse.executeScript("document.getElementById(‘email').value=“abc.efg@xyz.com”);

    Question-5
    What does the switchTo() command do?

    switchTo() command is used to switch between windows, frames, or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”.

    Get the window handle of the window you wish to switch to

    String handle= driver.getWindowHandle();

    Switch to the desired window

    driver.switchTo().window(handle);

    Alternatively

    for(String handle= driver.getWindowHandles())

    { driver.switchTo().window(handle); }

    Question-6
    How to upload a file in Selenium WebDriver?

    You can achieve this by using sendkeys() or Robot class method. Locate the text box and set the file path using sendkeys() and click on submit button

    Locate the browse button

    WebElement browse =driver.findElement(By.id("uploadfile"));

    Pass the path of the file to be uploaded using sendKeys method

    browse.sendKeys("D:\\SeleniumInterview\\UploadFile.txt");

    Question-7
    How to set browser window size in Selenium?

    The window size can be maximized, set, or resized

    To maximize the window

    driver.manage().window().maximize();

    To set the window size

    Dimension d = new Dimension(400,600);

    driver.manage().window().setSize(d);

    Alternatively,

    The window size can be reset using JavaScriptExecutor

    ((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768)");

    Question-8
    How do you find broken links in Selenium WebDriver?

    When we use driver.get() method to navigate to a URL, it will respond with a status of 200-OK

    200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken.

    Some of the HTTP status codes are :

    200 – valid Link
    404 – Link Not Found
    400 – Bad Request
    401 – Unauthorized
    500 – Internal error
    As a starter, obtain the links from the web application, and then individually get their status.

    Navigate to the interested webpage for e.g. www.amazon.com

    Collect all the links from the webpage. All the links are associated with the Tag ‘a‘

    List<WebElement> links = driver.findElements(By.tagName("a"));

    Create a list of types WebElement to store all the Link elements in it.

    for(int i=0; i<links.size(); i++) {

    WebElement element = links.get(i);

    String url=element.getAttribute("href");

    verifyLink(url); }

    Now Create a Connection using URL object( i.e ., link)

    URL link = new URL(urlLink);

    Connect using Connect Method

    HttpURLConnection httpConn =(HttpURLConnection)link.openConnection();

    Use getResponseCode () to get response code

    if(httpConn.getResponseCode()!== 200)

    Through exception, if any error occurred

    System.out.println(“Broken Link”);

    Question-9
    What is QTP?

    QTP (Quick Test Professional) is now known as HP UFT. It is a commercial automation tool and supports a very wide range of test environments Web, Desktop, SAP, Delphi, Net, ActiveX, Flex, Java, Oracle, Mobile, PeopleSoft, PowerBuilder, Siebel, Stingray, Visual Basic amongst others.

    The scripting language is VBScript. The tool gels well with HP ALM (Test Management Tool) and HP LoadRunner (Performance Testing Tool).

    Salient features of QTP include Business Process Testing, keyword-driven framework, XML support, robust checkpoints, test results.

    Question-10
    Explain what Sikuli is?

    Sikuli is a tool that uses "Visual Image Match" method to automate the graphical user interface. All the web elements in Sikuli should be taken as an image and stored inside the project.

    Sikuli is comprised of

    Sikuli Script
    Visual Scripting API for Jython
    Sikuli IDE
    Practical uses of Sikuli is that

    It can be used to automate flash websites or objects
    It can automate window based application and anything you see on screen without using internal API support
    It provides a simple API
    It can be easily linked with tools like Selenium
    Desktop application can be automated
    Sikuli offers extensive support to automate flash objects
    To automate desktop, it uses powerful "Visual Match" and Flash objects
    It can work on any technology-.NET, Java,

    Question-11
    What is the difference between Selenium and Sikuli?


    Sikuli
    It provides extensive support to automate flash objects
    It has a simple API
    It uses a visual match to find elements on the screen. So, we can automate anything we see on the screen
    It can automate the web as well as windows application

    Selenium
    It cannot automate flash objects like video player, audio player,
    It has got complicated API
    It does not have a visual match
    It can automate only web applications