EzDevInfo.com

webdriver interview questions

Top webdriver frequently asked interview questions

How to stop Selenium from creating temporary Firefox Profiles using Web Driver?

I am using Selenium Web Driver API with Java. Every time I want to debug my test cases, a temporary profile for Firefox is created in the temporary files directory. This is a headache in two ways.

  1. It definitely is taking unnecessary time to create a profile and is taking unnecessary space.
  2. I cannot install any addons that will be available next time I launch my test cases.

How do I get around this?


Source: (StackOverflow)

Is there a way to get element by Xpath using JavaScript in Selenium WebDriver?

I am looking for something like:

getElementByXpath(//html[1]/body[1]/div[1]).innerHTML

I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can't find it itself), but how?

I could use Id attribute, but not all elements have Id attribute.

[FIXED]

I am using jsoup to get it done in Java. That works for my needs. Thanks for the answers. :)


Source: (StackOverflow)

Advertisements

Selenium c# Webdriver: Wait Until Element is Present

I want to make sure that an element is present before the webdriver starts doing stuff.

I'm trying to get something like this to work:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5));
wait.Until(By.Id("login"));

I'm mainly struggling how to setup up the anynomous function..


Source: (StackOverflow)

WebDriver: check if an element exists?

How to check if an element exist with web driver?

Is using a try catch really the only possible way?

boolean present;
try {
   driver.findElement(By.id("logoutLink"));
   present = true;
} catch (NoSuchElementException e) {
   present = false;
}

Source: (StackOverflow)

Selenium WebDriver how to close browser popup

I am writing tests for a web App using selenium webDriver and came across a scenario where when I try to close the browser I get a popup saying "Are you sure? The page is asking you to confirm that you want to leave - data entered will be lost." with 2 buttons: Leave Page and Stay on Page

How do I click on those buttons?


Source: (StackOverflow)

Cucumber and Capybara, clicking a non-link or button element

I am trying to test an inplace editor using Cucumber/Capybara/Selenium stack, but my problem is that the editor is activated by clicking a div and not a link or button. I can not seem to figure out how to get Capybara to do this. Is there a way of doing this?


Source: (StackOverflow)

Get HTML Source of WebElement in Selenium WebDriver using Python

I'm using the Python bindings to run Selenium WebDriver.

from selenium import webdriver
wd = webdriver.Firefox()

I know I can grab a webelement like so...

elem = wd.find_element_by_css_selector('#my-id')

And I know I can get the full page source with...

wd.page_source

But is there anyway to get the "element source"?

elem.source   # <-- returns the HTML as a string

The selenium webdriver docs for Python are basically non-existent and I don't see anything in the code that seems to enable that functionality.

Any thoughts on the best way to access the HTML of an element (and its children)?


Source: (StackOverflow)

WebDriver switch to new browser opened after click on button

I have situation when click on button opens new browser instance with search results. Is there any way how I can to connect to new opened browser's window? And work with it, then return back to original browser (first window).

Thank you.


Source: (StackOverflow)

How to get HTTP Response Code using Selenium WebDriver with Java?

I have written tests with Selenium2/WebDriver and want to test if HTTP Request returns an HTTP 403 Forbidden.

Is it possible to get the HTTP response status code with Selenium WebDriver?


Source: (StackOverflow)

Unable to execute dex: Java heap space Java heap space

I am getting Unable to execute dex: Java heap space Java heap space error while executing web driver script in Eclipse IDE. I have configured Eclipse IDE with Android SDK and AVD Manager.

I also increased the -Xms200m to -Xmx512m but it did not work.


Source: (StackOverflow)

Take a screenshot with Selenium WebDriver

Does anyone know if it's possible to take a screenshot using Selenium WebDriver? (Note: Not Selenium RC)


Source: (StackOverflow)

WebDriver (Selenium 2) API documentation [closed]

I can't locate an official class/method/properties type API reference for WebDriver anywhere, only the 5 minute guide and Next Step pages located at seleniumhq, plus a few other haphazard descriptions. Does one exist?


Source: (StackOverflow)

what's the relationship between Selenium RC and WebDriver?

I can see that since selenium 2.0, WebDriver and Selenium RC are packaged together for download. Now I primarily use WebDriver, but can I bring in Selenium RC in my testing scripts from now and then? Is there anything that Selenium RC is capable of but WebDriver is not, or vice versa?


Source: (StackOverflow)

Wait for page load in Selenium

How do you make Selenium 2.0 wait for the page to load?


Source: (StackOverflow)

How to Using Webdriver Selenium for selecting an option in C#?

I was trying for my web test selecting an option. An example can be found here: http://www.tizag.com/phpT/examples/formex.php

Everything works great except the selecting an option part. How to selecting an option by value or by label ?

My Code:

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;

class GoogleSuggest
{
    static void Main()
    {
        IWebDriver driver = new FirefoxDriver();

        //Notice navigation is slightly different than the Java version
        //This is because 'get' is a keyword in C#
        driver.Navigate().GoToUrl("http://www.tizag.com/phpT/examples/formex.php");
        IWebElement query = driver.FindElement(By.Name("Fname"));
        query.SendKeys("John");
        driver.FindElement(By.Name("Lname")).SendKeys("Doe");
        driver.FindElement(By.XPath("//input[@name='gender' and @value='Male']")).Click();
        driver.FindElement(By.XPath("//input[@name='food[]' and @value='Chicken']")).Click();
        driver.FindElement(By.Name("quote")).Clear();
        driver.FindElement(By.Name("quote")).SendKeys("Be Present!");
        driver.FindElement(By.Name("education")).SendKeys(Keys.Down + Keys.Enter); // working but that's not what i was looking for
        // driver.FindElement(By.XPath("//option[@value='HighSchool']")).Click(); not working
        //  driver.FindElement(By.XPath("/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr/td/div[5]/form/select/option[2]")).Click(); not working
        // driver.FindElement(By.XPath("id('examp')/x:form/x:select[1]/x:option[2]")).Click(); not working

        }
} 

Source: (StackOverflow)