1

I am trying to enter a mobile number for our app. Still got error my android version is 4.4.4 This is the screenshot .This is a hybrid mobile app. I took Mycode: AndroidSetup

public class AndroidSetup {

    protected AndroidDriver driver;
protected void prepareAndroidForAppium() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.6.3");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4.4");
    capabilities.setCapability("deviceName", "Huawei");
    capabilities.setCapability("app", "/home/naveen/IdeaProjects/QberLoginPage/app/Qber_Customer_V1.6.0.apk");
    capabilities.setCapability("appPackage", "com.ionicframework.qber653346");
    capabilities.setCapability("appActivity", "MainActivity");
    driver = new AndroidDriver(new URL("http://192.168.1.10:4723/wd/hub"), capabilities);
    Set<String> contextNames = driver.getContextHandles();

    System.out.println(contextNames.size());

    for (String contextName : contextNames) {
        System.out.println(contextName);
        if (contextName.contains("WEBVIEW")){
            driver.context(contextName);
        }
    }
}

}

Login

public class Login extends BasePage {

    public Login(WebDriver driver) {
        super(driver);
    }

    public Login invalidLogin() {

        WebElement element = driver.findElement(By.className("text_field"));
        element.sendKeys("944556453");
        WebElement element1= driver.findElement(By.xpath("//*[@id=\'main\']/div[2]/div[1]"));
        element1.click();

            return new Login(driver);
            }
}

LoginTest

public class Logintest extends AndroidSetup {

    @BeforeClass
    public void setUp() throws Exception {
        prepareAndroidForAppium();
    }

    @AfterClass
    public void tearDown() throws Exception {
       // driver.quit();
    }

@Test
    public void login(){

    new Login(driver).invalidLogin();
}

Error report

2
NATIVE_APP
WEBVIEW_com.ionicframework.qber653346

org.openqa.selenium.WebDriverException: unknown error: cannot focus element
  (Session info: webview=33.0.0.0)
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-66-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 497 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'naveen-Inspiron-3542', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-66-generic', java.version: '1.8.0_121'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/home/naveen/IdeaProjects/QberLoginPage/app/Qber_Customer_V1.6.0.apk, appPackage=com.ionicframework.qber653346, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=192.168.1.8:5555, platform=LINUX, deviceUDID=192.168.1.8:5555, appActivity=MainActivity, desired={app=/home/naveen/IdeaProjects/QberLoginPage/app/Qber_Customer_V1.6.0.apk, appPackage=com.ionicframework.qber653346, appActivity=MainActivity, appium-version=1.6.3, platformVersion=4.4.4, platformName=Android, deviceName=Huawei}, appium-version=1.6.3, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: aa074358-2339-49e4-a077-4c4d9e402dbf

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

What should I do ?

0

a) To automate hybrid app make sure you change the context to Webview before finding out any elements. Following is the code to switch to webview.

       Set<String> contextNames = driver.getContextHandles();
        for (String context : contextNames) {
            if (context.contains(contextName)) {
                driver.context(context);
            }
        }

After this try finding an element.

b) While finding web elements in your app do not typecast element to MobileElement, your above code should be as follow.

WebElement element = driver.findElement(By.className("text_field"));

element.sendKeys("944556453");

WebElement element1= driver.findElement(By.xpath("//*[@id=\'main\']/div[2]/div[1]"));

element1.click();

EDIT: After editing question

For new error try below code to send data in input box...

WebElement element = driver.findElement(By.className("text_field"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys("SOME DATA");
actions.build().perform();
  • I edit my post please check – user24314 Mar 22 '17 at 9:49
  • @comrade Updated answer – Jeevan Bhushetty Mar 22 '17 at 9:56
  • @ Jeevan Bhushetty Thanks for the support dude.. – user24314 Mar 22 '17 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy