热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

appium无法在文本字段中输入

如何解决《appium无法在文本字段中输入》经验,求大佬解答?

我正在使用nativescript和nativescript-dev-appium进行端到端测试,并且试图在文本字段中输入一些文本。

我的xml布局中的textField;

      
           
           
      

      
        
        
        
      

我的规格;

import { AppiumDriver, createDriver, SearchOptions, nsCapabilities } from "nativescript-dev-appium";
import { assert } from "chai";
const addCOntext= require('mochawesome/addContext');

describe("sample scenario", () => {
    let driver: AppiumDriver;

    before(async function(){
        nsCapabilities.testReporter.cOntext= this; 
        driver = await createDriver();
    });

    after(async function () {
        await driver.quit();
        console.log("Quit driver!");
    });

    afterEach(async function () {
        if (this.currentTest.state === "failed") {
            await driver.logTestArtifacts(this.currentTest.title);
        }
    });

    it("should find an element by text", async function () {
        const nameField = await driver.findElementByAutomationText("name");
        await nameField.sendKeys("3d printer");

        const btnTap = await driver.findElementByAutomationText("create");
        await btnTap.click();
    });
});

我得到错误;

Error: [element.sendKeys("3d printer")] Error response status: 12, InvalidElementState - An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element). 
Selenium error: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '3d printer'. 
Did you interact with the correct element? at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:97) at 
io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37) at 
io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252) at 
io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243) at 
io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at 
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at 
io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435) at 
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) at 
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) at 
io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at 
io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at 
io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) at 
io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at 
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611) at 
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552) at 
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) at 
io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) at 
io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) at java.lang.Thread.run(Thread.java:761)

我也尝试过nameField.type(“ 3d打印机”)并得到相同的错误。

更新:尝试Xpath

it("should find an element by text", async function () {
    const nameField = await driver.findElementByXPath("//*[@automatiOnText='name']");
    await nameField.click();
    await nameField.sendKeys("3d printer");

出现错误

Error: [waitForElementByXPath("//*[@automatiOnText='name']",5000)] Element condition wasn't satisfied!

更新:按类名查找“ textfield”作品

如果我在测试中使用以下内容,并且表单上出现的第一个文本字段是名称字段,则此方法有效。

    const nameField = await driver.findElementByClassName(driver.locators.getElementByName("textfield"));
    await nameField.sendKeys("3d printer");

但是,如果不是第一个字段,如何选择文本字段?


推荐阅读
author-avatar
mobiledu2502899157
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有