created
Oct '18
last reply
Oct '18
- 36
replies
- 2.6k
views
- 7
users
- 2
likes
- 6
links
There are 36 replies with an estimated read time of 4 minutes.
There are 36 replies with an estimated read time of 4 minutes.
try {
AndroidElement list = (AndroidElement) mDriver
.findElement(By.id("dk.dsg.and.store.controllers:id/menu_list"));
MobileElement listGroup = list
.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().text(\"Kampagne info\"));"));
assertNotNull(listGroup.getLocation());
listGroup.click();
Result = mDriver.findElement(By.id("dk.dsg.and.store.controllers:id/textView")).getText();
System.out.println(Result);
Thread.sleep(5000);
if (Result.equals("BILKA - 1651 > Kampagne info")) {
mDriver.findElement(By.id("dk.dsg.and.store.controllers:id/btnBack")).click();
} else {
System.out.println(" No such Text Found Scenario FAIL");
}
} catch (Exception e) {
e.printStackTrace();
}
Try this…
Dimension size = this.wd.manage().window().getSize();
int startX = size.width / 2;
int startY = (int) (size.height * 0.60);
int endY = (int) (size.height * 0.30);
TouchAction action = new TouchAction(this.wd);
action.moveTo(PointOption.point(startX, endY));
new TouchAction(wd)
.press(PointOption.point(startX, startY))
.moveTo(PointOption.point(startX, endY))
.release().perform();
public static void scrollTo(String direction, int times) throws InterruptedException {
Thread.sleep(1000);
if (direction.equals(“down”)) {
Dimension dim = driver.manage().window().getSize();
int width = dim.getWidth() / 2;
for (int i = 0; i < times; i++) {
int startY = (int) (dim.getHeight() * 0.7);
int endY = (int) (dim.getHeight() * 0.5);
new TouchAction(driver).press(point(width, startY)).waitAction(waitOptions(Duration.ofSeconds(1)))
.moveTo(point(width, endY)).release().perform();
}
}
try this one please, and let me know the results.
Thanks,
Hi Sarah,
can you please share the code with me here
try {
AndroidElement list = (AndroidElement) mDriver
.findElement(By.id("**dk.dsg.and.store.controllers:id/menu_list"**)); // this is basically the ID of the list or the page as you highlight in the picture you need to paste the ID here in "************"
MobileElement listGroup = list
.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().text(\"Kampagne info\"));"));
assertNotNull(listGroup.getLocation()); // for assert you need to add jar file for testng or Junit as per your project
listGroup.click();// for listGroup you need to add jar for list group
Result = mDriver.findElement(By.id("dk.dsg.and.store.controllers:id/textView")).getText(); // for mDriver is my variable you need to user driver only instead of mDriver. and Result is String type variable you can intsert String before Result like String Result;
System.out.println(Result);
} catch (Exception e) {
e.printStackTrace();
}
comments are added on each error if you have still facing the issue kindly contact me Thanks
package project;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Scanner;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.offset.PointOption;
public class firstpro {static AppiumDriver driver = null;
public static void main(String[] args) {
caps.setCapability(“appPackage”, “com.daraz.android”);
caps.setCapability(“appActivity”, “com.lazada.activities.EnterActivity”);
caps.setCapability(“noReset”, true);
//Set ChromeDriver location
System.setProperty(“webdriver.chrome.driver”,“C:\Computer\PC\Documents\chromedriver_win32\chromedriver.exe”);
//Instantiate Appium Driver
try {
driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
scrollTo();
}
public static void scrollTo(String direction, int times) throws InterruptedException {
Thread.sleep(1000);
if (direction.equals(“down”)) {
Dimension dim = driver.manage().window().getSize();
int width = dim.getWidth() / 2;
for (int i = 0; i < times; i++) {
int startY = (int) (dim.getHeight() * 0.7);
int endY = (int) (dim.getHeight() * 0.5);
new TouchAction(driver).press(point(width, startY)).waitAction(waitOptions(Duration.ofSeconds(1)))
.moveTo(point(width, endY)).release().perform();
}
}
}
}
THIS IS MY CODE BUT ITS GIVING ERRORS. kindly tell me how to resolve it
Hi Sarah
Its really appreciated that you are struggling but the code which you share above is working with coordinates but the which i posted is working with text coordinates will change with the screen dimmision but the UIselector code which i share with you working with text so any type of application like native hybrid webapp can be handled with this code
Your code is pasted below in this i cannot understand what you required
public static void scrollTo(String direction, int times) throws InterruptedException {
Thread.sleep(1000);
if (direction.equals(“down”)) {
Dimension dim = driver.manage().window().getSize();
int width = dim.getWidth() / 2;
for (int i = 0; i < times; i++) {
int startY = (int) (dim.getHeight() * 0.7);
int endY = (int) (dim.getHeight() * 0.5);
new TouchAction(driver).press(point(width, startY)).waitAction(waitOptions(Duration.ofSeconds(1)))
.moveTo(point(width, endY)).release().perform();
so please use my code
which is easy i already comment on each line which you have mentioned as error
Everytime i execute your code, its giving me some errors so I have to change it to for the errors to be resolved
public static void scrollTo(String direction, int times) throws InterruptedException {
Thread.sleep(1000);
Object down = null;
if (direction.equals(down)) {
org.openqa.selenium.Dimension dim = driver.manage().window().getSize();
int width = dim.getWidth() / 2;
for (int i = 0; i < times; i++) {
int startY = (int) (dim.getHeight() * 0.7);
int endY = (int) (dim.getHeight() * 0.5);
new TouchAction(driver).press(point(width, startY)).waitAction(waitOptions(Duration.ofSeconds(1)))
.moveTo(point(width, endY)).release().perform();{
}
}
}
}
private static WaitOptions waitOptions(Duration ofSeconds) {
// TODO Auto-generated method stub
return null;
}
private static PointOption point(int width, int startY) {
// TODO Auto-generated method stub
return null;
}
and im calling it by scrollTo(“down”, 1);
But its still not working. Can you please help me with this?
i’m getting these errors do you know how to solve them?
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:13,“value”:“Drag did not complete successfully”}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 13 to UnknownError