当前位置: 首页 > 知识库问答 >
问题:

Appium驱动程序在应用程序的UI中找不到任何元素。尝试通过id、xpath和Name查找元素,但似乎没有任何效果

曹光霁
2023-03-14
package com.example;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.SessionId;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;

public class FirstAppiumTest {
    //protected AndroidDriver<AndroidElement> driver = null;
    public AppiumDriver driver;
    @BeforeTest
    public void Setup() throws MalformedURLException
    {String url = "http://127.0.0.1:4723/wd/hub";

        DesiredCapabilities cap=new DesiredCapabilities();

    cap.setCapability("noReset","true");
    cap.setCapability("deviceName","Redmi 4");
    cap.setCapability("platformVersion","7.1.2");
    cap.setCapability("platformName","Android");
    cap.setCapability("app","C:\\Appium\\selendroid-test-app.apk");



     driver=new AndroidDriver(new URL(url),cap);
    }
    @Test
    public void Simpletest() throws InterruptedException
    {  
        driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);
        //driver.findElement(By.className("android.widget.Button")).click();
        WebElement e1=driver.findElement(By.id("showToastButton"));
        e1.click();
         System.out.print(e1);
 String text=driver.findElement(By.className("android.widget.EditText")).getText();
     System.out.print(text);
     String src = driver.getPageSource();
       System.out.println(src);         
      driver.quit();


    }
}

暂时还没有答案

 类似资料:
  • 当我试图将元素放入元素中时,我面临一个问题。我尝试了两种方法来实现这一点,但不幸的是没有成功。 上面的代码获取所有DOM元素列表。 方法1: 当我尝试这个方法时,它总是返回第一个元素的文本,而不是相应的元素文本。 在搜索时,我发现了一个链接,有人问了和我一样的问题。 Selenium Webdriver在子元素中查找元素 当我尝试答案时,它给了我一个空白数组。 结果: 请建议我如何实现这一点,如何

  • 我无法让Selenium使用Internet Explorer驱动程序识别任何元素,无论使用的页面或选择类型如何。 通过xpath进行选择得到org。openqa。硒。InvalidSelectorException:无法计算xpath表达式“//body”,或者不会生成WebElement。其他选择类型也失败: 或 或 通过CSS选择器,名称或标记名称始终显示为org。openqa。硒。无接触异

  • 输入图片说明这里输入图片说明这里我无法在我的移动应用程序中找到使用appium的任何定位器的元素,请查看下面附上的屏幕截图和我的代码 Appium服务器响应 [debug][AndroidBootstrap][BOOTSTRAP LOG][debug]从客户端获取数据:{“cmd”:“ACTION”,“ACTION”:“find”,“params”:{“strategy”:“XPath”,“sel

  • 请帮助我,我正在尝试选择一个图片,这是一个链接(一个网站上的培训师) 这是我的代码:

  • 我是新来的。如果问题重复,很抱歉,但我没有找到解决方法。 我有一个问题--我无法使用Xpath定位元素,但我使用ID定位器定位它没有问题。见附件截图。这一问题不仅针对这一要素,而且也针对所有要素。看来Xpath根本不起作用。 我正在使用Appium 7.3.0(试用过不同版本),UIAutomator2,方法是在模拟器上设置,Android 8.1功能。 null 此外,我在需要的地方使用了和,因