I need to double tap with two fingers simulataneously on logo to proceed to next screen?
Yes, there exists a method to perform a double tab:
TouchActions action = new TouchActions(driver);
action.doubleTap(element);
action.perform();
You can try below code with help of touch action.
Define Mobile element as mentioned below
MobileElement mobileElement= (MobileElement) driver.findElement(by);
And pass this element to below function.
public void tapTwiceOnElement(MobileElement mobileElement) {
int halfHeight = element.getLocation().getX();
int halfWidth = element.getLocation().getY();
new TouchAction(driver).press(ElementOption.point(halfWidth,halfHeight)).release().perform().press(ElementOption.point(halfWidth,halfHeight)).release().perform();
new TouchAction(driver).press(ElementOption.point(halfWidth,halfHeight)).release().perform().press(ElementOption.point(halfWidth,halfHeight)).release().perform();
}
this is a Java code for two finger double tap, in case anyone needs it:
Preconditions: you can change withPosition to withElement and x and y values need to be predefined.
MultiTouchAction secondTwoFingerPress = new MultiTouchAction(DeviceBucket.getDriver());
secondTwoFingerPress.add(new TouchAction(DeviceBucket.getDriver())
.tap(TapOptions.tapOptions()
.withPosition(PointOption.point(xPoint, yPoint))
.withTapsCount(2)));
secondTwoFingerPress.add(new TouchAction(DeviceBucket.getDriver())
.tap(TapOptions.tapOptions()
.withPosition(PointOption.point(xPoint1, yPoint1))
.withTapsCount(2)));
secondTwoFingerPress.perform();
Based on appium documentation: https://appium.io/docs/en/writing-running-appium/touch-actions/
You can use MultiTouch gesture.
Pseudocode example of tapping with two fingers:
action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()
Related
I am trying to automate an app which is built using recyclerview. There are totally 10 tiles and in one screen 1st four tiles will be visible and to get other tiles I need to move the screen upward. I tried to move the screen by finding co-ordinates and "(AndroidElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceIdMatches(\".*id/type_text\")).setMaxSearchSwipes(5).scrollIntoView("new UiSelector().text(\"" + text + "\"))"))" this but there is slightly movement in the screen and couldn't get the remaining tiles. Is there any way to scroll to the bottom of the screen so that I can get last tile also.
Please try this. I think there's some issue in your UiScrollable..
MobileElement listItem=(MobileElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()"
+ ".scrollable(true)).scrollIntoView("
+ "new UiSelector().text(\"<Mention your element text value here>\"))"));
#Sammar Ahmad, yes you were right. I was using wrong element. I constantly tried and finally worked after using co-ordinates.Code looks something like below. Created scroll() in homepage class and called the same from my test class
public void scroll(int x, int y) {
int startY = (int) (driver.manage().window().getSize().getHeight() * 0.90);
int endY = (int) (driver.manage().window().getSize().getHeight() * 0.10);
TouchAction action = new TouchAction(driver);
action.press(point(x, startY)).waitAction(waitOptions(ofSeconds(3))).moveTo(point(x, endY)).release().perform();
}
MobileElement startElement = (MobileElement) driver.findElementById("mention parent element here");
Point location = startElement.getLocation();
homepage.scroll(location.x,location.y);
MobileElement listItem=(MobileElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"<Mention your element text value here>\"))"));
You can modify #sammar's code like this to scroll to the element.
I'm Trying to capture the Co-ordinates of Maps to do some action on Maps.
wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.`path`("//button[contains(text(),'Add Tract')]"))).click();
Utils.scrollUp();
Thread.sleep(10000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("TimeZoneId")));
//Timezone is the area which I'm trying to capture the Co-Ordinates
Point point1 = timezone.getLocation();
SOP("Element's Position from left side is: "+point1.getX()+" pixels.");
SOP("Element's Position from top is: "+point1.getY()+" pixels.");
}
if your map has <canvas> tag, then try
To perform using Actions chains, below is an example C# code similar to Java
IWebElement canvas = driver.FindElement(By.Id("TimeZoneId"));
int xCo = canvas.Location.X;
int yCo = canvas.Location.Y;Actions action = new Actions(driver);
action.MoveToElement(canvas, 1 + xCo, 2 + yCo).Click().Build().Perform();
Try OpenCV
If you are testing overlays on map. use JavaScriptExecutor and by adding hooks to your code in order to perform actions in your Map.
Try with Sikuli (personally, I have not used this. Needs some research)
I wrote following piece of code to move a draggable object on
https://jqueryui.com/draggable/
driver.get("https://jqueryui.com/draggable/");
WebElement eleFrame=driver.findElement(By.className("demo-frame"));
driver.switchTo().frame(eleFrame);
WebElement ele=driver.findElement(By.xpath("//*[#id='draggable']"));
Actions move=new Actions(driver);
move.dragAndDropBy(ele, 180, 300).release().build().perform();
This code does not move the object.
when i tried
move.clickAndHold(ele).moveByOffset(300, 100).release().build().perform();
it is working fine.I read the documnets it is saying dragAndropBy have internally same functionality as clickAndHold and then moving by some offset.
I have tested it before for both vertical/horizontal slider and it used to work fine.
Please suggest what is the problem with dragAndDropBy code. or some other functionality is actually expected out of it.
Any help will be much appreciated.
Actually it's pretty weird that move.clickAndHold(ele).moveByOffset(300, 100).release().build().perform(); is working for you... I've tried them both and they throw the same exception:
org.openqa.selenium.UnsupportedCommandException: moveto did not match a known command
However, there are open bugs in Selelnium and in geckodriver on this issue.
BTW, the only difference between the two is that you don't have the ButtonReleaseAction in your custom action.
You can use dragAndDrop() method.
Actions action = new Actions(driver);
action.dragAndDrop(sourceElement, destinationElement).build().perform();
Refere tutorial http://www.seleniumeasy.com/selenium-tutorials/drag-and-drop-using-webdriver-action-class
No need to release() When "dragAndDropBy" is used.
Try this:
move.dragAndDropBy(ele, 180, 300).build().perform();
Multiple Controls Drag and Drop to the Same Destination.
WebElement element_1 = driver.findElement(By.xpath("//li[#data-lobid='12']")); //source element 1
WebElement element_2 = driver.findElement(By.xpath("//li[#data-lobid='21']")); //source element 2
WebElement destination = driver.findElement(By.xpath(".//*[#id='lobModalPopUp']/div")); //destination path
int[] array_source = new int[]{12,21}; // create fixed array for id number of source element 1 and 2
for(int i = 0; i<array_source.length; i++) //Passing id number of source element 1 and 2 inside the for loop.
{
WebElement all_source_element = driver.findElement(By.xpath("//li[#data-lobid='"+arraylobs[i]+"']")); // getting all source element with the help of fixed array.
Actions drag = new Actions(driver);
drag.clickAndHold(all_source_element).build().perform();
Thread.sleep(3500);
drag.clickAndHold().moveToElement(destination).release(destination).build().perform();
Thread.sleep(3500);
}
driver.get("https://jqueryui.com/draggable/");
driver.switchTo().frame(0);
WebElement dragMe = driver.findElement(By.cssSelector(".ui-draggable-handle"));
new Actions(driver).dragAndDropBy(dragMe, dragMe.getLocation().getX()+100, dragMe.getLocation().getY()+100).perform();
This is how to use the dragAndDropBy(WebElement source, int xOffset, int yOffset) method provided in Actions class to perform drag and drop operations.
WebElement source: web-element that you want to drag around.
int xOffset and int yOffset are future x-axis and y-axis coordinate positions. Basically, the code gets the current x-axis and y-axis coordinate positions and adds int number to move the draggable element.
Please make sure to set up your driver properly before using this block of code.
I have tried with below codings for swiping.
While running the test case, the swipe action doesn't occurs and I am also not getting any error message.
How can I swipe on both side from left to right and vice-versa.
There are two methods which are as follows:-
Method 1(using TouchActions):-
1. //Swipe Right to Left side of the Media Viewer First Page
WebElement firstPages = driver.findElement(By.id("media-list"));
TouchActions flick = new TouchActions(driver).flick(firstPages,-100,0,0);
flick.perform();
2. //perform swipe gesture
TouchActions swipe = new TouchActions(driver).flick(0, -20);
swipe.perform();
Method 2 (using javascript):-
public static void swipe(WebDriver driver) {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new java.util.HashMap<String, Double>();
swipeObject.put("startX", 0.95);
swipeObject.put("startY", 0.5);
swipeObject.put("endX", 0.05);
swipeObject.put("endY", 0.5);
swipeObject.put("duration", 1.8);
js.executeScript("mobile: swipe", swipeObject);
}
Try following implementation which inlcudes standard FlickAction.SPEED_NORMAL argument and also action builder for flick:
import org.openqa.selenium.interactions.touch.FlickAction;
private Action getBuilder(WebDriver driver) {
return new Action(driver);
}
WebElement toFlick = driver().findElement(By.id("media-list"));
Action flick = getBuilder(driver()).flick(toFlick, -500, 0, FlickAction.SPEED_NORMAL).build();
flick.perform();
Swiping from left to right and vice verse can be performed by varying X-asis coordinates:
Swipe to the left:
Action flick = getBuilder(driver()).flick(toFlick, -500, 0,
FlickAction.SPEED_NORMAL).build();
Swipe to the right:
Action flick = getBuilder(driver()).flick(toFlick, 500, 0, FlickAction.SPEED_NORMAL).build();
Swipe to the top:
Action flick = getBuilder(driver()).flick(toFlick, 0, 500, FlickAction.SPEED_NORMAL).build();
Swipe to the bottom:
Action flick = getBuilder(driver()).flick(toFlick, 0, -500, FlickAction.SPEED_NORMAL).build();
A common reason for actions just completely failing to work when functionally testing JavaScript heavy web sites is that the actions are taken before the site has finished initialising. The simplest way to test this is the case is to add a short sleep before performing the action. Say 2 seconds.
If this solves the problem then you know you have a race condition between the page initialising and your test code running.
At that point you can rewrite your code to wait for the action to be possible.
I know this is an old question, but I encountered a number of similar problems with this.
As others have pointed out, it's generally a timing thing. So I found that if I waited for an element to be present (i.e. the driver has returned control and the page has rendered), and then did a brief sleep both before and after the flick action, it works, certainly on every page/app I've tested it with. So our code looks a bit like this:
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("some-element-id)));
flickIt(driver, element -100, 0);
private void flickIt(WebDriver driver, WebElement el, int x, int y) {
SyntheticsUtility.sleep(500); // put 0.5s sleeps around it to make sure, need to be stable
TouchActions touch = new TouchActions(driver);
touch.flick(el, x, y, FlickAction.SPEED_NORMAL);
touch.perform();
SyntheticsUtility.sleep(500);
}
I want to move two bodies on a android phone using two separate touch's, Is this possible?
You can get coordinates of first and second touch with following methods
int firstX = Gdx.input.getX(0);
int firstY = Gdx.input.getY(0);
int secondX = Gdx.input.getX(1);
int secondY = Gdx.input.getY(1);
Use them to move your objects.
You can read more in libgdx documentation