EzDevInfo.com

selenium-webdriver interview questions

Top selenium-webdriver frequently asked interview questions

Wait for page load in Selenium

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


Source: (StackOverflow)

Difference between webdriver.Dispose(), .Close() and .Quit()

What is the difference between these

  1. Webdriver.Close()
  2. Webdriver.Quit()
  3. Webdriver.Dispose()

Which one to be used and when?


Source: (StackOverflow)

Advertisements

Debugging "Element is not clickable at point" error

I see this only in Chrome.

The full error message reads:

"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..."

The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page.

I have tried adding an offset, but that does not work either. The item is on the displayed window without any need for scrolling.


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)

Random "Element is no longer attached to the DOM" StaleElementReferenceException

I'm hoping it's just me, but Selenium Webdriver seems like a complete nightmare. The Chrome webdriver is currently unusable, and the other drivers are quite unreliable, or so it seems. I am battling many problems, but here is one.

Randomly, my tests will fail with a

"org.openqa.selenium.StaleElementReferenceException: Element is no longer attached 
to the DOM    
System info: os.name: 'Windows 7', os.arch: 'amd64',
 os.version: '6.1', java.version: '1.6.0_23'"

I'm using webdriver versions 2.0b3. I have seen this happen with FF and IE drivers. The only way I can prevent this is to add an actual call to Thread.sleep before the exception occurs. That is a poor workaround though, so I'm hoping someone can point out an error on my part that will make this all better.


Source: (StackOverflow)

Selenium WebDriver - Test if element is present

is there a way how to test if an element is present? Any findElement method would end in an exception, but that is not what I want, because it can be that an element is not present and that is okay, that is not a fail of the test, so an exception can not be the solution.

I've found this post: Selenium c# Webdriver: Wait Until Element is Present But this is for C# and I am not very good at it. Can anyone translate the code into Java? I am sorry guys, I tried it out in Eclipse but I don't get it right into Java code.

This is the code:

public static class WebDriverExtensions
{
    public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
    {
        if (timeoutInSeconds > 0)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
            return wait.Until(drv => drv.FindElement(by));
        }
    return driver.FindElement(by);
    }
}

Source: (StackOverflow)

Selenium: FirefoxProfile exception Can't load the profile

Per this previous question I updated Selenium to version 2.0.1 But now I have another error, even when the profile files exist under /tmp/webdriver-py-profilecopy:

  File "/home/sultan/Repository/Django/monitor/app/request.py", line 236, in perform
    browser = Firefox(profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 46, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
    self._wait_until_connectable() 
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 87, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile Dir : %s" % self.profile.path)
selenium.common.exceptions.WebDriverException: Can't load the profile. Profile Dir : /tmp/webdriver-py-profilecopy

What is wrong? How can I resolve this issue?


Source: (StackOverflow)

Getting the return value of Javascript code in Selenium

I'm using Selenium2 for some automated tests of my website, and I'd like to be able to get the return value of some Javascript code. If I have a foobar() Javascript function in my webpage and I want to call that and get the return value into my Python code, what can I call to do that?

(I'm asking this question because I can't find the answer anywhere on the web and answer the question myself below.)


Source: (StackOverflow)

How to select option in drop down using Capybara

I'm trying to select an item from a drop down menu using Capybara (2.1.0).

I want to select by number (meaning select the second, third, etc option).

I've Googled like crazy trying all sorts of things but no luck.

I was able to select it by using the value:

 find("option[value='4c430d62-f1ba-474f-8e8a-4452c55ea0a8']").click

But I don't want to use that method b/c the value is something that will change and that will make my test brittle.

The HTML for the drop down is:

<td class="value">
    <select name="organizationSelect" id="organizationSelect" class="required">
     <option value="NULL">Choose...</option>
     <option value="4c430d62-f1ba-474f-8e8a-4452c55ea0a8">&nbsp;Institution1</option>
     <option value="e1a4efa7-352d-410a-957e-35c8a3b92944">&nbsp;Institution / test</option>
    </select>
</td>

I also tried this:

  option = find(:xpath, "//*[@id='organizationSelect']/option[2]").text  
  select(option, :from => organizationSelect)

But it results in this error:

Ambiguous match, found 2 elements matching option "Institution" (Capybara::Ambiguous)

So how can I select the first, second, third, etc option from the drop down (using Capybara) ?


Source: (StackOverflow)

How to run Selenium WebDriver test cases in Chrome?

I tried this

WebDriver driver = new ChromeDriver();

But i'm getting the error as

Failed tests: setUp(com.TEST): The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

How can I make Chrome to test the Selenium-WebDriver test cases?


Source: (StackOverflow)

Selenium::WebDriver::Error::JavascriptError: waiting for evaluate.js load failed Firefox 23

Today running my rspec tests, I get the following error whenever somewhere in a test theres a `page.execute_script' call.

 Selenium::WebDriver::Error::JavascriptError:
   waiting for evaluate.js load failed
 # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:8360:in `r'
 # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:392:in `fxdriver.Timer.prototype.runWhenTrue/g'
 # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:386:in `fxdriver.Timer.prototype.setTimeout/<.notify'

There is a file evaluate.js in the /resources directory (instead of components) of the path above, as it is on other machines.

This happened after updating to Firefox 23 from 22. I haven't been able to rollback yet to confirm that returning to 22 indeed fixes the problem, but that's all that's changed I believe.

Has anyone else seen this problem?

Running Kubuntu 12.04, Capybara 1.1.4, selenium-webdriver gem 2.33.0

I tried updating Capybara to 2.whatever and selenium-webdriver to 2.34.0, no change.


Source: (StackOverflow)

How to perform mouseover function in Selenium WebDriver using Java?

I want to do mouseover function over a drop down menu. When we hover over the menu, it will show the new options. I tried to click the new options using the xpath. But cannot click the menus directly. So, as the manual way i am trying to hover over the drop down menu and then will click the new options.

Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath("//html/body/div[13]/ul/li[4]/a"));
action.moveToElement(we).build().perform();

Source: (StackOverflow)

How can I ask the Selenium-WebDriver to wait for few seconds in Java?

I'm working on a Java Selenium-WebDriver. I added

driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

and

WebElement textbox = driver.findElement(By.id("textbox"));

because my Applications takes few seconds to load the User Interface. So I set 2 seconds implicitwait. but I got unable to locate element textbox

Then I add Thread.sleep(2000);

Now it works fine. Which one is a better way?


Source: (StackOverflow)

Unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

While testing scenario by cucumber i'm getting the following error when running rspec tests

unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)

Using ruby (1.9.2) selenium-webdriver (2.27.2) and firefox (19.0)

Using rspec-rails (2.12.1), capybara (2.0.2) and several other gems, Also i have added launchy gem but they don't seem to be a problem. And i am using Windows 7.


Source: (StackOverflow)

Firefox WebDriver doesn't work with Firefox 32

I've just updated to Firefox 32, when I attempt to run my Selenium Webdriver Test, Im getting the following

Failed to start up socket within 45000 ms. Attempted to connect to the
following addresses: 127.0.0.1:7055 OpenQA.Selenium.WebDriverException
was unhandled by user code   HResult=-2146233088   Message=Failed to
start up socket within 45000 ms. Attempted to connect to the following
addresses: 127.0.0.1:7055   Source=WebDriver   StackTrace:
       at OpenQA.Selenium.Firefox.FirefoxDriverServer.ConnectToBrowser(TimeSpan
timeToWait)
       at OpenQA.Selenium.Firefox.FirefoxDriverServer.Start()
       at OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command
commandToExecute)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
desiredCapabilities)
       at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor, ICapabilities desiredCapabilities)
       at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, ICapabilities capabilities, TimeSpan
commandTimeout)
       at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, TimeSpan commandTimeout)
       at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile)
       at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()
       at SMT.Web.FunctionalTests.Drivers.Driver.GetWebDriver(Int32 browser, String page)

I was expecting to be able to run the tests as per normal.

Has anyone experiencing the same thing? How did you resolve the issue?

Selenium version: 2.41.0 (Installed as a Nuget Package) OS: Windows 7 Browser: Firefox Browser version: 32


Source: (StackOverflow)