I have scenario that after scroll setting screen click on logout button. but unfortunately there is one News button nearer to logout button show everytime when i click on logout button it everytime click on news button due to that I am not able to logout from app and not able to successfully complete script.
Below is code for same
package appiumUbuntu;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class ScrollANDLogout {
public static void main(String args[]) throws InterruptedException, MalformedURLException
{
DesiredCapabilities desire =new DesiredCapabilities();
desire.setCapability("deviceName", "Lenovo A7010A48");
desire.setCapability("udid", "OVLV45CEQW7P49NJ"); //Give Device ID of your mobile phone
desire.setCapability("platformName", "Android");
desire.setCapability("platformVersion", "6.0");
desire.setCapability("appPackage", "com.euradvance.classstars");
desire.setCapability("appActivity", "com.configureit.citapp.CITScreen");
desire.setCapability("noReset", "true");
//Setup Appiumdriver
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), desire);
Thread.sleep(3000);
//Enter Email id
WebElement email = driver.findElement(By.xpath("//android.widget.TextView[@text='Email*']"));
email.sendKeys("lee@mailinator.com");
// email.sendKeys(Keys.TAB);
//Enter password
// Thread.sleep(5000); LABEL8
Thread.sleep(1000);
WebElement password = driver.findElement(By.id("textfield_password"));
password.click();
password.sendKeys("password");
//Click on Login button
WebElement login_button =driver.findElement(By.id("button_login"));
login_button.click();
//Click on Settings button
Thread.sleep(3000);
WebElement home_settings =driver.findElement(By.id("button_setting"));
// Thread.sleep(3000);
home_settings.click();
//Scroll screen
/*Thread.sleep(3000);
WebElement log_out =driver.findElement(By.id("BUTTON2"));
TouchActions action = new TouchActions(driver);
action.scroll(log_out,10 , 100);
action.perform();*/
// log_out.click();
Thread.sleep(3000);
MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"com.euradvance.classstars:id/view_forms\")).getChildByText("
+ "new UiSelector().className(\"android.widget.EditText\"), \"Log Out\")"));
//Perform the action on the element
//System.out.println(element);
Thread.sleep(3000);
MobileElement logout =driver.findElement(By.id("textfield_logout"));
//element.click();
//MobileElement logout =driver.findElement(By.xpath("//android.widget.EditText[@text='Language']"));
String str =logout.getText();
System.out.println(str);
//Thread.sleep(3000);
Actions builder = new Actions(driver);
builder.moveToElement(logout, -30, 0).build().perform();
builder.click();
//logout.click();
}
}