Unable to click on the button on version 7,8.1

Hello everyone,

I have tried to click on the save button and also the other buttons but I am not able to do it. I have run the case on Android version 7.0 (Moto G4 Plus) and version 8.1 (Samsung On6). When I run it on version 7.1.1 (Lenovo K8 plus), the code is able to run automatically without any error. Can someone provide any solution to it as I am stuck on this for a couple of days? Also, have applied all types of the wait.

did you tried with other functions? class, id or index?

Hello Chetan.

Thanks for the reply. Yes I have tried it. It actually does not work with other elements too. The whole screen actually goes non responsive.

Elements that used:

  1. id - tvSave
  2. xpath - //android.widget.TextView[@text=‘Save’]
  3. xpath - //android.widget.TextView[@text=‘Save’ and @index = 1]

Please do let me know if any more elements can be made.

Note: This only occurs on some devices as mentioned in the description.

try to find with uiautomator.

driver.findElementByAndroidUIAutomator(“text(“Views”)”).click();

Validate clickable feature for all options.

i didn’t used this function yet but you can find out more on google.

Hi Chetan,

Thanks for the reply. It’s actually giving an error of syntax error. Please, can you tell me as to why you have used (“text(“Views”)”)? I am getting a syntax error. Also, thanks for sharing the link provided. I am still unable to find the solution in it. Could you please suggest some more. I have even tried
driver.findElements(By.xpath ("//*[@class=‘android.widget.TextView’ and @index=‘1’]"));
as mentioned in one of the comments.

that’s how you can use uiautomator.
here is code.
// driver.findElementByAndroidUIAutomator(“attribute(“value”)”)

     driver.findElementByAndroidUIAutomator("text(\"Views\")").click();
     
    // driver.findElementByAndroidUIAutomator("text(\"Views\")").click();
     
   //  Validate clickable feature for all options
     //  driver.findElementsByAndroidUIAutomator("new UiSelector().property(value)");  
 System.out.println(driver.findElementsByAndroidUIAutomator("new UiSelector().clickable(true)").size()); 
     
}

Hi Chetan,

Thanks for the reply. I am still not able to click on the element. Can you please write the code for
driver.findElementByAndroidUIAutomator(“attribute(“value”)”) as suggested by you. The id I wanna click is tvSave. Also, the screenshot is added. Kindly check if you need anything else. I have written the code but I am not able to do it.

//MobileElement save = ((AndroidDriversession.driver).findElementByAndroidUIAutomator(“new UiSelector().text(“Save”)”);

List elementsTextContainsTO = ((AndroidDriver)session.driver).findElementsByAndroidUIAutomator(“new UiSelector().textContains(“Save”)”);

Kindly suggest.

i need time, i will send you full code in 2 days.

Sure. Thanks chetan.

is there all class name same.
if yes than try this.
// driver.findElementByXPath("(//class)[index]").click();
// in your case

driver.findElementByXPath("(//android.widget.TextView)[0]").click();

you can change 0 if same class is on second place in array.

or try

driver.findElementByAndroidUIAutomator(“text(“Save”)”).click();

hope this going to help.

Hi Chetan,

Thanks for the reply. I have tried both the elements that you have provided. Unfortunately, this is still not working fine.

  1. driver.findElement(By.xpath("(//android.widget.TextView)[0]")).click();
  2. driver.findElement(By.xpath("//android.widget.TextView[0]")).click();
  3. ((AndroidDriver) driver).findElementByAndroidUIAutomator(“text(“Save”)”).click();

I have also changes the index in the 1 and 2. Still it does not work.

Please do let me know if there is any other option other than this.
Thanks.

it will find all elements not element and will click 1st as value is get(0).

driver.findElementsByClassName(“android.widget.TextView”).get(0).click();

Hi chetan,

Thanks for the reply. I have also tried this.

Listelements = (List) session.driver.findElements(By. className (“android.widget.TextView”));

elements.get(0).click();

Please can you suggest something other than this.

Actually, the issue is that the whole screen goes un responsive. Thus I am not able to click on any button. Kindly let me know if any other thing can be done.

reason should be something else. i don’t have another suggestion.

Yeah, I guess. I am able to run it on Lenovo K8 plus version 7.1.1 and Motorola X play version 5.0. but not on other phones.