Can't click on element even though it's there


#1

I’m facing this problem where I cant find an element with my test even though it’s there

org.openqa.selenium.NoSuchElementException:
An element could not be located on the page using the given search parameters.

The element is there.

Here is the code… The problem happens at the method
"click_order()"

package admin_app;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ActiveOrders {
	AndroidDriver driver;
	String AppPackage = "com.thoag.admin.thoagadmin";
	String AppActivity = ".WelcomeActivity";

	@BeforeTest
	public void setUp() throws MalformedURLException{
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("browserName", "Android");
		capabilities.setCapability("platformName","Android");   
		capabilities.setCapability("appPackage", AppPackage);
		capabilities.setCapability("appActivity",AppActivity);
		URL url = new URL("http://localhost:4723/wd/hub");
		driver  = new AndroidDriver(url, capabilities);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}
	
	@Test
	public void test() throws Exception{
		login("email","pass");
		click_order();
	}

	@AfterTest
	public void teardown(){
		//close the application
		driver.quit();
	}
	
	
	public void login(String email, String password) throws InterruptedException {
		//Get started
		driver.findElement(By.id("com.thoag.admin.thoagadmin:id/button4")).click();
		Thread.sleep(2000);
				
		//fill email and password then click Login	
		MobileElement emailElement = (MobileElement) driver.findElement(By.id("com.thoag.admin.thoagadmin:id/editText"));
		emailElement.setValue(email);
		driver.hideKeyboard();
				
		MobileElement passwordElement = (MobileElement) driver.findElement(By.id("com.thoag.admin.thoagadmin:id/editText2"));
		passwordElement.setValue(password);
		driver.hideKeyboard();
			
		driver.findElement(By.id("com.thoag.admin.thoagadmin:id/button")).click();
	}
	
	private void click_order() throws InterruptedException {
    	Thread.sleep(3000);
    	driver.findElement(By.id("com.thoag.admin.thoagadmin:id/tab_delivered")).click();
}

}