1

I am trying to run the sample project given in Android sdk but I am getting the error:

could not find the element with name:q

Here is the sample code:

{
driver.get("google.com"); 
WebElement searchBox = driver.findElement(By.name("q")); 
searchBox.sendKeys("Android Rocks!"); 
searchBox.submit(); 
String title = driver.getTitle(); 
assertTrue("Got title: " + title, title.contains("Google")); 
assertTrue(driver.findElements(By.partialLinkText("Android")).size() > 1);
}

I am running the tests on emulator(version 2.2).

6
  • And does the internal browser at least load properly the google page? Commented Mar 15, 2013 at 9:53
  • Please explain the situation detail!!!! Commented Mar 15, 2013 at 10:04
  • yep. In this case I can only recommend to add some waiting. Probably you search for the element too early after loading the page... Commented Mar 15, 2013 at 10:07
  • 1
    Xeena- the code i am trying to run is: driver.get("google.com"); WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("Android Rocks!"); searchBox.submit(); String title = driver.getTitle(); assertTrue("Got title: " + title, title.contains("Google")); assertTrue(driver.findElements(By.partialLinkText("Android")).size() > 1); But i am getting an exception since it could not find the element "q". Commented Mar 15, 2013 at 10:26
  • @pavel:i am new to android web driver.can you please tell how can i put wait??is it by using driver object?? Commented Mar 15, 2013 at 10:28

1 Answer 1

1

Please read my more complete answer to the more recent (and complete) question. The link is below:

ANDROID webdriver with selenium


I've left the following answer just in case it's also useful...

Neha, first things first, have you read the relevant wiki page for Android driver on the Selenium project? http://code.google.com/p/selenium/wiki/AndroidDriver

As it says, the last version of Android WebDriver to support Android 2.2 is release 2.16 of the APK, http://code.google.com/p/selenium/downloads/detail?name=android-server-2.16.apk

If you would prefer to use the current versions of the Android driver I would recommend you try using newer versions of Android e.g. 2.3 as a minimum. As you may know, it's easy to create a new emulator, a new AVD as they're also known, that has 2.3

If you're still stuck once you've either tried using 2.16 of Android-WebDriver in your 2.2 emulator, or the current version of Android-WebDriver in an emulator with 2.3 or later of Android, perhaps you could add the stack trace and the complete Java source for your code online here. That'd help people to help you :) Good luck Julian.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks.i'll let you know if it's working.Does android 2.2 support the "sendKeys" event??
If you want to know more about android 2.2 and the "sendKeys' event please can you create a new question on stackoverflow (once you've done your research too :) that way you can "show your workings" to help us to help you more effectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.