gpt4 book ai didi

java - 设置值方法设置值太快

转载 作者:太空宇宙 更新时间:2023-11-04 09:32:23 25 4
gpt4 key购买 nike

setValue 方法将值放入字段的速度太快,并在过程中丢失一些字符。sendKeys 方法也无法正常工作。

[https://pp.userapi.com/c849532/v849532534/1d4fe6/BEVb5_C3O8E.jpg][]

Appium服务器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");

}

}

我需要找到一种稍微延迟一点的设置值的方法或其他方法,这可以帮助我解决这个问题。

最佳答案

您可以使用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\")");

关于java - 设置值方法设置值太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56931879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com