2016-07-07 102 views
0

嘗試使用appium for android本機應用登錄用例。但按鈕點擊不起作用。但我正在通過所有測試。還與移動驅動程序進行了交流。Appium android button click not working?

 @BeforeClass 
     public static void setUp() throws MalformedURLException 
     { 
      DesiredCapabilities capabilities=new DesiredCapabilities(); 
     capabilities.setCapability("BROWSER_NAME","Chrome"); 
      capabilities.setCapability("VERSION","4.3"); 
      capabilities.setCapability("deviceName","SGH-T999L"); 
      capabilities.setCapability("platformName","Android"); 
      capabilities.setCapability("appPackage","org.odk.collect.android"); 
      capabilities.setCapability("appActivity","com.fieldforce.android.activities.LoginActivity"); 
      webDriver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); 

    //  webDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); 
     } 
     @Test 
     public void testLogin() throws Exception 
     { 
    //  webDriver.switchTo().window("NATIVE_APP"); 
      WebDriverWait wait = new WebDriverWait(webDriver, 10); 
      WebElement userName= webDriver.findElement(By.id("txt_username")); 
      userName.sendKeys("733894"); 
      WebElement password= webDriver.findElement(By.id("txt_password")); 
      password.sendKeys("[email protected]"); 

      WebElement login_button= webDriver.findElement(By.id("org.odk.collect.android:id/btn_login")); 

      wait.until(ExpectedConditions.visibilityOf(login_button)); 
      login_button.click(); 



     } 

@AfterClass 
    public static void tearDown() 
    { 
     webDriver.quit(); 
    } 
+0

你如何證明點擊不起作用?任何彈出窗口或錯誤都必須確認,不是嗎? – nullpointer

+0

我點擊服務器。沒有得到迴應 –

+0

可以請你分享服務器日誌,在你的應用程序在設備/模擬器預計什麼行動? – nullpointer

回答

0

建議使用

WebElement login_button= webDriver.findElement(By.id("btn_login")); //as used for other WebElement 

此外,我相信一般的登錄頁面應理想地具有登錄可見,如果不是這樣的話,你可能想在頁面上進行向下滾動而不是

wait.until(ExpectedConditions.visibilityOf(login_button)); 

PS - 如果你收到任何錯誤/異常後這個。請添加到問題,讓我們知道。

+0

沒有得到錯誤或異常,但點擊功能不起作用 –

0

當然,測試會通過,因爲您只是想單擊登錄按鈕,測試用例是否應該通過或失敗,除非您在單擊登錄按鈕後添加一些Assert並不重要。

嘗試登錄加入一些等待點擊後

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

然後嘗試斷言在@test東西方法TESTLOGIN喜歡添加以下兩條語句的中端,並使其與定位你登錄後得到兼容

Actualtext = driver.findElement(By.xpath("locator to verify after login")).getText(); 
Assert.assertEquals(Actualtext, "assert Text"); 
0

我得到了同樣的問題。

請確保您的提交按鈕(UI)未被電話鍵盤覆蓋。

如果覆蓋,解決方案: 在運行單擊[.click()]功能之前隱藏鍵盤。

鍵盤隱藏代碼是在這裏How to dismiss the keyboard in appium using Java?

原因: 怎麼把Appium點擊使用X &ŸUI座標的按鈕,如果鍵盤覆蓋了提交按鈕,它點擊鍵盤上不上的按鈕。

+1

感謝這工作。 –