简体   繁体   English

无法为appium中的应用程序元素设置Xpath

[英]Not able to set Xpath for my application elements in appium

I am totally new in Appium. 我完全是Appium的新手。 Here I am just trying to do a basic test (WebView context) for my login page app. 在这里,我只是尝试对我的登录页面应用程序进行基本测试(WebView上下文)。 Everything is working fine but I am not able to send values to the two input fields. 一切工作正常,但我无法将值发送到两个输入字段。 Please help me out ...Thank you.. 请帮帮我...谢谢

index.html:- index.html:-

 <label class="item_input">
      <a class="item item-icon-left in-text">
        <i class="icon ion-email iconEmail"></i>
        <div class="term"> <input  id="email"type="email" placeholder="Email" class="in-text" ng-model="loginData.username" name="email" required></div></a>

      </label>
      <span style="color:white" ng-show="loginForm.username.$dirty && loginForm.username.$invalid">
        <label ng-show="loginForm.username.$error.required">Email is required</label>
      </span>
      <label class="item_input">
        <a class="item item-icon-left in-text1">
          <i class="icon ion-key iconKey"></i>
          <div class="term">  <input  id="password"type="password" placeholder="Password" class="in-text" ng-model="loginData.password"name="password" required></div></a>
        </label>
        <span style="color:white" ng-show="loginForm.password.$dirty && loginForm.password.$invalid">
          <label ng-show="loginForm.password.$error.required">Password is required.</label>

        </span>

my appiumTest.java:- 我的appiumTest.java:-

@Test
public class AppiumTest {

    private static AndroidDriver driver;

    public static void main() throws MalformedURLException, InterruptedException {
        DesiredCapabilities capabilities = new DesiredCapabilities();



        // Optional

        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");


        // Specify the device name (any name)

        capabilities.setCapability("deviceName", "Nexus");


        // Platform version

        capabilities.setCapability("platformVersion", "6.0.1");


        // platform name

        capabilities.setCapability("platformName", "Android");


        // specify the application package that we copied from appium                

        capabilities.setCapability("appPackage", "XXXXXXXX");


        // specify the application activity that we copied from appium                   

        capabilities.setCapability("appActivity", "XXXXXXXX");

        // Start android driver I used 4727 port by default it will be 4723

            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);


        driver.findElement(By.xpath("//input[@id='email']")).sendKeys("hello");
        driver.findElement(By.xpath("//input[@id='password']")).sendKeys("hello");
        // Wait for 10 second

        // Wait for 10 second

        Thread.sleep(10000);



        // close the application
         driver.quit();


    }

}

Error in eclipse:- 蚀错误:-

FAILED: main
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 78 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'ZANDIG-PC', ip: '192.168.15.2', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_76'
*** Element info: {Using=xpath, value=//input[@id='email']}
Session ID: 6d48a8e9-9c5f-4b77-acf5-1905fe2ea853
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=LINUX, javascriptEnabled=true, appActivity=com.orionorbit.th.MainActivity, browserName=, networkConnectionEnabled=true, desired={platformVersion=6.0.1, platformName=Android, deviceName=Nexus, appActivity=com.orionorbit.th.MainActivity, browserName=, appPackage=com.orionorbit.th}, locationContextEnabled=false, appPackage=com.orionorbit.th, platformVersion=6.0.1, databaseEnabled=false, platformName=Android, deviceName=0c35ec7f02ba5d2f, webStorageEnabled=false, warnings={}, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:67)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:145)
    at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:63)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at Appium.AppiumTest.main(AppiumTest.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

Based on that error, it looks like your test is throwing on 根据该错误,看来您的测试正在进行中

driver.findElement(By.xpath("//input[@id='email']")).sendKeys("hello");

which seems to be line 61 for you. 这似乎是您的第61行。 This means that there's a problem finding by xpath, which may be due to the syntax. 这意味着通过xpath查找存在问题,这可能是由于语法所致。

One problem is that the 'required' attribute is left unassigned. 一个问题是'required'属性未分配。 Another problem is that the tag is never closed. 另一个问题是标签永远不会关闭。

Try this for the input tag. 尝试输入标签。 The difference is that the 'required' attribute is gone and the tag is closed: 区别在于'required'属性不存在,并且标记已关闭:

<input id="email" type="email" placeholder="Email" class="in-text" ng-model="loginData.username" name="email"/>

If you want to quickly test how else you can use xpath, pay a visit to this link . 如果您想快速测试xpath的其他用法,请访问此链接

Hope I could help :) 希望我能帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM