Not able to click on an element in Appium - android

My UI Automator Viewer Screenshot
I want to click on Play Now button and tried the following code:
driver.findElement(By.xpath("//android.view.View[contains(#content-desc,'Play Now')]"));
and this code:
driver.findElement(By.name("Play Now!"));
These codes are not showing any error but not clicking on Play Now button even.
Please help.

try this one
driver.findElementByAccessibilityId("content written on the button").click();

If you feel your Xpath is right but you are not click on that means that is because of synchronization problem. Just give time to find the element and click. Try like below example
Thread.sleep(5000);
driver.findElement(By.xpath("//android.view.View[contains(#content-desc,'Play Now')]")).click();
Thread.sleep(5000) gives 5 second time to search for the element. This should work in your case.
if click works fine not need to use any waits.
You can further use implicit or explicit wait once you are perfect with your automation.

Related

'this#ActivityName' is not captured error Android/Kotlin

I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText:
And XML:
This is how it looks when debugging:
The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?
All the best!
fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.
if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})
sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.
I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:
First enter debugger mode inside of your anonymous callback,
In your debugger console, look at the right side for "Frames"
Within Frames under , you'll see stack of function execution first top one on the list is the latest:
Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
When you see you AddInformationActivity instance, you can expand it and see its variables.
Hope that helps!
It's not a beautiful way, but if you create a method like this:
private fun debug() {
println()
}
and add a breakpoint on the println() it'll capture the activity.
(Don't use TODO as it'll crash the app with a NotImplementedError once called.)
I have this method now in my code all the time to call it whenever I need it.
I know, that question is old, but I just stumbled over it and needed a way.

Finding an element by id in Appium

I have got id associated with the element, but when tried locating this using findElement(By.id()) it doesn't work.
Also, I had gone through few blogs with the same question as given here, but I saw the resource-id in there was prefixed with packagename and :id. In my case, these aren't associated. Screenshot for the element details is below :
I have used the below code to locate the element by id.
- driver.findElement(By.id("loginHome"));
- driver.findElement(By.id("com.packagename:id/loginHome"));
- driver.findElement(By.id("android:id/loginHome"));
- driver.findElement(By.xpath(//*[#id='loginHome']));
But none of the above code snippets worked. Can someone please help me get through with this. Thanks in Advance.
Not exactly answering your question, but providing an alternative method for you to complete the test.
I follow this link https://github.com/appium/appium-dot-app and it works.
You don't need to code everything. The application provides some easy ways to record your clicks and gestures.
For example, when I click something, it will print out the script automatically.
wd.find_element_by_xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]").click()
And you just need to choose your favorite programming language and save it after testing is done.
One thing that I have to point out is that the swipe function is corrupted. Use the following code to perform swipe gestures
wd.swipe(421, 424, 70, 424, 500)
You can try other options as well. Try this:
//add some wait command before the element
Thread.sleep(2000);
driver.findElementsByXPath("//*[#class='android.widget.Button' and #index='4']");
Try adding explicit sleep for page to load before clicking usind ID.
First try to wait for the particular element
MobileElement expelement=(MobileElement) (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.Button[#index='4']")));
Then try to do the click(or the activity you suppose to do)
driver.findElement(By.xpath("//android.widget.Button[#index='4']")).click();

In Appium Sendkeys didn't work as expected, it sends more than i give to it

I'm using Appium to write test cases of an Android application, when i tap the following code
public void EnterQuantity() {
wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[3]/android.widget.LinearLayout[3]/android.widget.LinearLayout[1]/android.widget.EditText[1]")).sendKeys("1");
}
I get 11 in Quantity field instead of 1.
How can i reduce the speed of writing in order to be sure that only the number i gave is written not doubled.
Try changing your Auto-Correction setting from Language & Input Setting in android Device manually
#Emna I beleieve it calls the EnterQuantity() twice . try to add click element(eg. submit button) inside this function to narrow down the root cause

Problems with Listpicker App Inventor

I'm a beginner at App Inventor and I don't know what I'm doing wrong with the listpicker.
I am trying to create and app to reproduce the music I have stored in my server but when i display the listpicker I can't click any of the options and also I can't go back to the first screen. Here I put my code:
Image 1
Image 2
I tried to remove the line that says call listpicker.open but it only made appear a totally black screen.
The result of the code I just posted is exactly what I spect a list with the name and the link of the 2 songs I already upload to my server but when I click them it didn't do anything.
Thanks for your help.
The Web component works asynchronously, which means, it takes a little bit, until the result is available. The result you will get in the Web.GotText event.
Therefore it does not make sense to call the updateListpicker procedure in the Listpicker.BeforePicking event, because the result still is not available and you get displayed an empty listpicker. The listpicker will be opened, before you have received the result!
Set the listpicker to visible=false and use a button.click event to call the updateListpicker procedure. Then as you already do it in the Web.GotText event, assign the received list to the listpicker and open it.

Android Graphical UI Builders - Connect event

Maybe this question has been ask already, but could not find any answer for almost 2hours of internet search.
There is a graphical UI designer wich is coming along with the last android SDK.
Looks pretty cool and well done.
Nevertheless I * cannot find how to attach an event to the control through the graphical editor.
Of course I can add it manually into the xml, but in that case, what's the purpose of having such tool without that function ?
I mean all the other SDK I had in other languages always include that function.
I've also not been able to find doc about how to use this tool. Quite sad...
Thanks
If you want to add a click event handler, select the button (widget) in the GUI that you want to listen for, and look for the property onClick. Enter the name of the method you want to call when the user clicks on that widget, like.. onMyButtonClick
Then add the method to your Activity
public void onMyButtonClick(View v) {
// I heard the button click
}
The GUI builder is getting there, and is not yet as easy to use as the one in XCode, but it's not hard when you get used to it.

Categories

Resources