Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run the below code but getting error. Can you please point out the issue?

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class SelTe2 {

public static void main(String[] args) {

    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("network.proxy.type", 2);
    firefoxProfile.setPreference("network.proxy.autoconfig_url", "");
    firefoxProfile.setPreference("network.proxy.no_proxies_on", "localhost");

    // Open Bing Search Engine
    WebDriver wd = new FirefoxDriver(firefoxProfile);

    // Search for Kotak and navigate to Net Banking Secure Login 
    WebElement we1 = wd.findElement(By.xpath("//input[contains(@title, 'search')]"));
    wd.findElement(By.xpath("//li/a[text()='Net Banking']")).click();
    wd.findElement(By.xpath("//a/img[@title='NetBanking Secure Login']")).click();

    // Switch to child window
    for (String handles : wd.getWindowHandles()) {
        if (!wd.getTitle().contains(wd.getWindowHandle())){

    // Wait for 15 sec. while page loads
    wd.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    // Enter Username and Password


Error Description: -

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"name","selector":"Username"} Command duration or timeout: 15.06 seconds For documentation on this error, please visit: Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56' System info: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_43' Session ID: 73e4a32c-9447-4242-a13b-7bc5a9f21406 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=20.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable( at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed( at org.openqa.selenium.remote.RemoteWebDriver.execute( at org.openqa.selenium.remote.RemoteWebDriver.findElement( at org.openqa.selenium.remote.RemoteWebDriver.findElementByName( at org.openqa.selenium.By$ByName.findElement( at org.openqa.selenium.remote.RemoteWebDriver.findElement( at SelTe2.main( Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"name","selector":"Username"} Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56' System info: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_43' Driver info: driver.version: unknown at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/DOCUME~1/SS0041~1/LOCALS~1/Temp/anonymous5139644307112851862webdriver-profile/extensions/ at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/DOCUME~1/SS0041~1/LOCALS~1/Temp/anonymous5139644307112851862webdriver-profile/extensions/

share|improve this question
Error is thrown on the last section where I enter Username. – Saik0 May 2 '13 at 11:47
It may help for you to specify the error message. – user246 May 2 '13 at 14:13
Are you sure there is an element with the name "Username"? Is the element in an iframe? – Sam Woods May 2 '13 at 17:38
@SamWoods This is what inspect element says - <td class="trLogin" bgcolor="#d3d3d3" align="left" valign="top"><input class="loginTextbox" type="text" maxlength="50/" onfocus="setFlag(this);" onkeypress="return checkExclusive('userid')" name="Username"></input></td> – Saik0 May 2 '13 at 20:50
Further up the tree, is that td inside of an iframe? – Sam Woods May 2 '13 at 20:59
up vote 5 down vote accepted

In your comment you mentioned that the element is within a <frameset> \ <frame>. To work with any element within a frame, you need to first switch the context of the driver from the main page to that frame:


In this example "foo" would be the name of the iframe. You can also do it by index if the frame has no name value.

If you need to switch back to the main page, outside of the frame you would use: driver.switchTo().defaultContent();

There is a little more detail in the documentation: Look for switchTo().frame

share|improve this answer
Bingo! It worked!! Thanks Sam :) – Saik0 May 6 '13 at 6:01

Try using something as follows :-

WebDriverWait wait = new WebDriverWait(driver, 60);// 1 minute 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.