I am trying to do swipe operation using swipe(direction, duration) method in appium. But swipe method is getting deprecated.And getting exception on console
FAILED: test
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
This is my code
MobileElement abc = (MobileElement) driver.findElement(By.className("android.widget.FrameLayout"));
abc.swipe(SwipeElementDirection.UP, 6000);
I think swipe() method is not available. PFA screenshot for reference.
1)eclipse screen shot
https://i.stack.imgur.com/PRTdw.png
2)Methods unavailable screen shot
https://i.stack.imgur.com/kzygI.png
swipe() method from driver has been deprecated in the latest versions of Appium. Not only swipe(), even tap(), pinch(), zoom() have also been deprecated.
You would now have to use TouchActions to perform swipe operation. Sample code -
TouchAction touchAction = new TouchAction(driver);
touchAction.press(startX, startY).moveTo(endX, endY).release().perform();
Related
I am new of mobile app automation tested using Appium with TestNG.Am practicing to automate amazon app, App was launching successfully but when I try to click login option, it's getting:
"FAILED: login org.openqa.selenium.NoSuchElementException: An
element could not be located on the page using the given search
parameters. (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 0 milliseconds"
public void login() throws InterruptedException{
System.out.println("Login check");
Thread.sleep(3000);
// String sample = driver.findElementByXPath("//*[#class='android.widget.Button' and #index='5']").getText();
System.out.println("Next sleep");
// driver.findElement(By.xpath("//[#class='android.widget.Button' and #index='5']')]")).click();
// driver.findElement(By.id("in.amazon.mShop.android.shopping:id/sign_in_button")).click();
driver.findElement(By.xpath("//android.widget.Button[#index='5']")).click();
Thread.sleep(3000);
System.out.println("Pass");
}
Image:
"//android.widget.Button[#index='5']" is invalid xpath locator. If you will ever what to use index (but I strongly suggest not to do it), do it this way:
"(//android.widget.Button)[5]"
But in your case the best is to search by resource-id:
driver.findElement(By.id("sign_in_button")).click();
And if it still doesn't work you can print app screen xml structure just before you search for element:
System.out.println(driver.getPageSource())
Analyse the xml you get if it contains your button and what are the attributes of it.
Please try this code:
MobileElement el1 = (MobileElement) driver.findElementById("in.amazon.mShop.android.shopping:id/sign_in_button");
el1.click();
So some background information. I am tasked with exploring writing cross platform native applications using Xamarin. Seems pretty basic so far and I'm liking what I'm reading. I have my Visual Studio 2015 Enterprise all set up and my remote mac configured on the network. I created a cross platform native app through the project creation wizard in Visual Studio. When I launch a debug session for the iOS app, it does start the target app in the simulator on the remote Mac. However, it never actually thinks it is running fully. It will hang at this output:
Launching 'PersonalProject.iOS' on 'iPhone 6 iOS 10.2'...
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/Xamarin.iOS.dll
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.dll
Thread started: #2
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/PersonalProject.iOS.exe
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.Xml.dll
Eventually, it will fail with something along these lines:
The app has been terminated.
Launch failed. The app 'PersonalProject.iOS' could not be launched on 'iPhone 6 iOS 10.2'. Error: An error occurred while executing MTouch. Please check the logs for more details.
I've checked the log file in question and it contains nothing more than the same exact phrase.
If I try and put a simple line of Console writing on the action of pressing the button:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
Button.AccessibilityIdentifier = "myButton";
Button.TouchUpInside += delegate {
var title = string.Format ("{0} clicks!", count++);
Button.SetTitle (title, UIControlState.Normal);
Console.WriteLine(string.Format("{0} clicks!"));
};
}
the debug session actually errors on this line 17 (UIApplication.Main) in the Main.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace PersonalProject.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}
With Unhandled exception error:
Unhandled Exception:
System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Error while resolving expression: One or more errors occurred.
If I don't have the console log it will launch the app, but still hanges at those Loaded assembly lines. At this point, I can't hit any breakpoints in my code. I tried adding a breakpoint in the shared code for the button click but it would never hit it, even though the action was being carried out by the simulator.
I'm completely at a loss for how to proceed. I haven't touched anything out of the box of the wizard creation. I was hoping I could at least see the starter project working.
Any help is appreciated.
You are using
Console.WriteLine(string.Format("{0} clicks!"));
The {0} is a placeholder for a value to output, but you never specify that value, that's why you are getting an error.
Use something like this instead:
Console.WriteLine(string.Format("{0} clicks!", count));
or in C#6 syntax:
Console.WriteLine($"{count} clicks!");
I'm using this code in order to find an element on my Android (Native App) device using selenium and Appium :
var wait = new WebDriverWait(_driver,TimeSpan.FromSeconds(15));
var phone = wait.Until(x => x.FindElements(By.Id("foo")));
The problem is that Selenium finds the element only seemingly. Meaning it finds it, but with no attributes at all.
But when using :
System.Threading.Thread.Sleep(5000)
everything works like a charm.
I have tried to increase the seconds in the driver's wait, but it didn't help.
I think the element is not getting loaded at the time script is performing an operation on it.
Try to add a visibility check before performing any operation on that element
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.locator);
I created a cordova app using sencha touch 2.4 framework and sencha cmd, It works on iOS and the majority of Android devices.
The problem appears on some old devices like Galaxy Ace and GT-B5510 for example.
It get stuck on the blue loading screen and throws this error:
09-12 23:43:41.386: E/Web Console(373): TypeError: Result of expression 'b.onTargetTouchMove.bind' [undefined] is not a function. at file:///android_asset/www/app.js:1
is there any solution for this problem or i just have to exclude these devices?
This seem to be the same issue as described and answered in the following post:
Sencha touch 2.4 appLoadingIndicator stack on android 2.3.
ECMAScript 5 not supported on old android devices :
please replace this
if (Ext.feature.has.Touch) {
// bind handlers that are only invoked when the browser has touchevents
me.onTargetTouchMove = me.onTargetTouchMove.bind(me);
me.onTargetTouchEnd = me.onTargetTouchEnd.bind(me);
}
with
if (Ext.feature.has.Touch) {
// bind handlers that are only invoked when the browser has touchevents
me.onTargetTouchMove = Ext.Function.bind(me.onTargetTouchMove, me);
me.onTargetTouchEnd = Ext.Function.bind(me.onTargetTouchEnd, me);
}
I am new to Appium and have been trying to automate the Conversion Calculator app for Android. Am getting the error "org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters", when trying to find a EditText element. Using Appium ver 1.0.0 and Android 4.3
The following is my code:
List<WebElement> textViews = driver.findElements(By.className("android.widget.TextView"));
for (i=0; i<textViews.size(); i++) {
if(textViews.get(i).getText().toLowerCase().contains("memory")) {
textViews.get(i).click();
}
}
Thread.sleep(5000);
WebElement editText = driver.findElement(By.className("android.widget.EditText"));
editText.sendKeys("123");
Even findElement by ID is not working. Please let me know what I am doing wrong here or if I need to provide more details.
I would use
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); instead of Thread.sleep(5000).
Try to use a newer version of Appium, I's been improved a lot. You can download the latest version of Appium and Appium clients here:http://appium.io/downloads.html
But be careful because in the newer version the findElement throws an Exception if there are more then one result of the search.
I would write this in a comment but I've not enough reputation :/
Possible Cause:
Multiple EditText in the current screen.
Please try with the following:
Solution1:
List<WebElement> editText = driver.findElements(By.className("android.widget.EditText"));
editText.get(0).sendKeys("123");
0 - Index of EditText
Solution2:
Use any other locating strategy like Xpath.
Maybe you could try waiting until the element is visible or enabled using a WebDriverWait object?
Avoid using sleep as much as possible, try using the WAIT command.
Sleep without waiting for the time that has been determined, even if the element is already on the screen.
In the case of the wait command, as soon as the element appears, the action will already be performed, this along the code will reduce the execution time considerably.
The issue for me was the app path I was using. If you are using a config file make sure to declare the application separately from the device.
If not, make sure the "app" capability has the right path. Here is the code in my config file for example:
devices_by_ids = {
"platformName": "Android",
"appium:DEVICE ADB ID": {
"android_version": "13",
"device_name": "google_Pixel_5a",
"DEVICE ADB ID": "DEVICE ADB ID",
"port":"4723",
"autoGrantPermissions": "true",
},
"appium:app": "YOUR APP PATH",
"appium:appWaitActivity": "*"
}
In Appium v2 use
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));