setValue方法将值放在字段中的速度过快,并且在处理过程中丢失了一些字符。 sendKeys方法也无法正常工作。
[https://pp.userapi.com/c849532/v849532534/1d4fe6/BEVb5_C3O8E.jpg][]
Appium Server 1.13.0
package appiumtests2;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import static java.lang.Thread.sleep;
public class Stoloto {
/*
* static WebDriver driver;
* AndroidDriver driver;
*/
static AppiumDriver<MobileElement> driver;
public static void main(String[] args) {
try {
Stoloto stoloto = new Stoloto();
stoloto.openStoloto();
} catch (Exception exp) {
System.out.println(exp.getCause());
System.out.println(exp.getMessage());
exp.printStackTrace();
}
}
@Test
public void openStoloto() throws Exception {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Pixel XL");
cap.setCapability("udid", "HT6B70200690");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "9");
cap.setCapability("appPackage", "ru.stoloto.mobile");
cap.setCapability("appActivity", "ru.stoloto.mobile.ca.presentation.ui.activity.MainActivity");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url, cap);
System.out.println("Application Started...");
MobileElement onBoardContinue = driver.findElement(By.id("ru.stoloto.mobile:id/confirm"));
onBoardContinue.click();
onBoardContinue.click();
MobileElement onBoardLogin = driver.findElement(By.id("ru.stoloto.mobile:id/login"));
onBoardLogin.click();
MobileElement loginField = driver.findElement(By.id("ru.stoloto.mobile:id/user"));
String login = "testtesttest@gmail.com";
sleep(1000);
loginField.setValue(login);
MobileElement passwordField = driver.findElement(By.id("ru.stoloto.mobile:id/passwordInputEdit"));
String password = "qwertyqwerty";
sleep(1000);
passwordField.setValue(password);
driver.hideKeyboard();
MobileElement log_in = driver.findElement(By.id("ru.stoloto.mobile:id/buttonSubmit"));
log_in.click();
System.out.println("Test Completed");
}
}
我需要找到一种延迟设置值的方法或另一种方法,这可以帮助我解决此问题。
答案 0 :(得分:0)
您可以使用mobile:shell
命令通过adb shell向设备发送文本
Map<String, Object> argv = new HashMap<>();
argv.put("command", "input");
argv.put("args", Lists.newArrayList("text", "your_text_here"));
driver.executeScript("mobile: shell", argv);
或者,您可以考虑使用Appium SeeTest Extension可用的elementSendText
函数
driver.executeScript("seetest:client.elementSendText(\"NATIVE\", \"id=your_element_id\", \"0\", \"your_text_here\")");
答案 1 :(得分:0)
您是否尝试过使用WebDriverWait来设置值?