android selenium

I am using webdriver for android for automation of website testing. I have done all the things with installation of web driver and i open google page.but it dont take the searching item i entered.here it is "Cheese".I mentioned the code below .please suggest solution. Thanks

public class AndroidSeleniumActivity extends TestCase 
{
    /** Called when the activity is first created. */

    public void testGoogle() throws Exception 
{
        AndroidDriver driver = new AndroidDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");

        // Find the text input element by its name
        WebElement element =  driver.findElement(By.xpath("html/body/div[2]/div[1]/div[1]/div[2]/div[2]/div/form/fieldset [2]/div/div/div/table/tbody/tr/td[2]/div/input[3]"));

        // Enter something to search for
        element.sendKeys("Cheese!");

       // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page

        // Remember to close the WebDriver connection to free up resources on the
        // Android device (or emulator). Pause for 30 seconds first so we can see
        // the results of the search.
       // Thread.sleep(30000L);
        driver.quit();
      }

}

Answers


Use id or name to find the element(Search text field) instead of using

XPATH: WebElement element =  driver.findElement(By.xpath("html/body/div[2]/div[1]/div[1]/div[2]/div[2]/div/form/fieldset [2]/div/div/div/table/tbody/tr/td[2]/div/input[3]"));

Use this and it will work:

WebElement element =  driver.findElement(By.name("q"));

Need Your Help

PHP syntax to call methods on temporary objects

php object oop temporary

Is there a way to call a method on a temporary declared object without being forced to assign 1st the object to a variable?

ImportError in running django from twisted

python django twisted python-import

I'm trying to run a Twisted program, which serves some requests and also runs a Django app through WSGI, and routes some requests to it. Folder structure is something like this: