问题描述
限时送ChatGPT账号..以下是我尝试点击的按钮的 html 代码.
The following is the html code for the button that I'm trying to click.
<Button rounded style={styles.pickBtn} title="get started" onPress={signIn} testID="completeBoarding">
<Text style={styles.pickBtnText}>GET STARTED</Text>
</Button>
这是我试图用来单击所述按钮的代码.
This is the code that I have tried to use to click on said button.
String xPath = "//button[normalize-space()='GET STARTED']";
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.xpath(xPath)));
searchElement.click();
-
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("get started")));
searchElement.click();
-
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("GET STARTED")));
searchElement.click();
从上面提供的html,点击按钮的正确方法是什么?我试过的上述方法都没有成功运行.每个都失败,并显示一条错误消息,指出无法找到该元素.
From the html provided above, what is the correct way to click the button? Neither of the above methods I tried ran successfully. Each failed with an error message saying that the element could not be found.
推荐答案
请尝试使用以下代码点击.
Please try with below code to click.
String xPath = "//*[@title='get started']";
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.xpath(xPath)));
searchElement.click();
使用文本点按:
您可以使用 text
和 UiAutomator2
点击如果您使用 appium
作为自动化引擎,请添加所需的功能 UiAutomator2
.
You can tap using text
with UiAutomator2
Add in desired capability UiAutomator2
if you are using appium
as automation engine.
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
然后使用这个函数
public void TapByText(String buttonText) {
String buttonName="new UiSelector().text(\"MY_TEXT\")".replace("MY_TEXT", buttonText);
@SuppressWarnings("unchecked")
List<WebElement> el = (List<WebElement>) driver.findElements(MobileBy.AndroidUIAutomator(buttonName));
System.out.println(el.size());
new TouchAction(driver).press(ElementOption.element(el.get(0))).waitAction().release().perform();
}
这篇关于Appium无法在Android设备上找到按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论