我正在使用appium的客户端编写一些Java代码。我成功地输入了输入文本的页面,但是,进入页面后,输入字段没有响应。
这是结构:
<?xml version="1.0" encoding="UTF-8"?>
<hierarchy rotation="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" ]" resource-id="" instance="0">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" ]" resource-id="" instance="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" 4]" resource-id="android:id/content" instance="1">
<android.webkit.WebView index="0" text="" class="android.webkit.WebView" 4]" resource-id="" instance="0">
<android.webkit.WebView index="0" text="" class="android.webkit.WebView" content-desc="Home" focused="true" scrollable="true" 4]" resource-id="" instance="1">
<android.widget.Button index="0" text="" class="android.widget.Button" content-desc="纬 " checkable="false" checked="false" clickable="true" " resource-id="" instance="0"/>
<android.view.View index="1" text="" class="android.view.View" content-desc="Sign Up Page" checkable="false" checked="false" clickable="true" 36]" resource-id="" instance="0"/>
<android.view.View index="2" text="" class="android.view.View" content-desc="Home" checkable="false" checked="false" clickable="true" 6]" resource-id="" instance="1"/>
<android.widget.Button index="3" text="" class="android.widget.Button" content-desc="sign up " checkable="false" checked="false" clickable="true" 48]" resource-id="" instance="1"/>
<android.widget.Button index="4" text="" class="android.widget.Button" content-desc=" Clean Time Logs " checkable="false" checked="false" clickable="true" 8]" resource-id="" instance="2"/>
<android.view.View index="5" text="" class="android.view.View" scrollable="true" 84]" resource-id="" instance="2">
<android.widget.Image index="0" text="" class="android.widget.Image" content-desc="PEGI_gambling" checkable="false" checked="false" clickable="true" 78]" resource-id="" instance="0"/>
<android.view.View index="1" text="" class="android.view.View" content-desc="Welcome!" checkable="false" checked="false" clickable="true" 342]" resource-id="" instance="3"/>
<android.view.View index="2" text="" class="android.view.View" content-desc="anonymous" checkable="false" checked="false" clickable="true" 404]" resource-id="" instance="4"/>
<android.view.View index="3" text="" class="android.view.View" 90]" resource-id="" instance="5">
<android.widget.Image index="0" text="" class="android.widget.Image" content-desc="white-dove" checkable="false" checked="false" clickable="true" 88]" resource-id="" instance="1"/>
</android.view.View>
<android.view.View index="4" text="" class="android.view.View" content-desc="This is the home page of the mobile app. The right hand most button is for switching page. Bottom is the time logs of clicking button or changing the views. The button at the subheader is used for cleaning all time logs." checkable="false" checked="false" clickable="true" 184]" resource-id="" instance="6"/>
<android.view.View index="5" text="" class="android.view.View" content-desc="*The Like, Comment are fake." checkable="false" checked="false" clickable="true" 1184]" resource-id="" instance="7"/>
<android.view.View index="6" text="" class="android.view.View" 1184]" resource-id="" instance="8">
<android.view.View index="0" text="" class="android.view.View" content-desc="Like" checkable="false" checked="false" clickable="true" 1184]" resource-id="" instance="9"/>
<android.view.View index="1" text="" class="android.view.View" content-desc="Comment" checkable="false" checked="false" clickable="true" ,1184]" resource-id="" instance="10"/>
</android.view.View>
</android.view.View>
<android.view.View index="6" text="" class="android.view.View" scrollable="true" 1184]" resource-id="" instance="11">
<android.view.View index="0" text="" class="android.view.View" 1184]" resource-id="" instance="12">
<android.view.View index="0" text="" class="android.view.View" content-desc="Account & Personal Info" checkable="false" checked="false" clickable="true" 316]" resource-id="" instance="13"/>
<android.view.View index="1" text="" class="android.view.View" 430]" resource-id="" instance="14">
<android.view.View index="0" text="" class="android.view.View" content-desc="Username" 418]" resource-id="_label-0" instance="15">
<android.view.View index="0" text="" class="android.view.View" content-desc="Username" checkable="false" checked="false" clickable="true" 404]" resource-id="" instance="16"/>
</android.view.View>
<android.widget.EditText index="1" text="" class="android.widget.EditText" content-desc="e.g. woody" checkable="false" checked="false" clickable="true" ,408]" resource-id="" instance="0"/>
</android.view.View>
<android.view.View index="2" text="" class="android.view.View" 544]" resource-id="" instance="17">
<android.view.View index="0" text="" class="android.view.View" content-desc="Email" 532]" resource-id="_label-1" instance="18">
<android.view.View index="0" text="" class="android.view.View" content-desc="Email" checkable="false" checked="false" clickable="true" 518]" resource-id="" instance="19"/>
</android.view.View>
<android.widget.EditText index="1" text="" class="android.widget.EditText" content-desc="1232@gmail.com" checkable="false" checked="false" clickable="true" ,522]" resource-id="" instance="1"/>
</android.view.View>
<android.view.View index="3" text="" class="android.view.View" 658]" resource-id="" instance="20">
<android.view.View index="0" text="" class="android.view.View" content-desc="Password" 646]" resource-id="_label-2" instance="21">
<android.view.View index="0" text="" class="android.view.View" content-desc="Password" checkable="false" checked="false" clickable="true" 632]" resource-id="" instance="22"/>
</android.view.View>
<android.widget.EditText NAF="true" index="1" text="" class="android.widget.EditText" checkable="false" checked="false" clickable="true" ,636]" resource-id="" instance="2"/>
</android.view.View>
<android.view.View index="4" text="" class="android.view.View" 772]" resource-id="" instance="23">
<android.view.View index="0" text="" class="android.view.View" content-desc="Birthday" 760]" resource-id="_label-3" instance="24">
<android.view.View index="0" text="" class="android.view.View" content-desc="Birthday" checkable="false" checked="false" clickable="true" 746]" resource-id="" instance="25"/>
</android.view.View>
<android.widget.Spinner NAF="true" index="1" text="" class="android.widget.Spinner" checkable="false" checked="false" clickable="true" ,750]" resource-id="" instance="0"/>
</android.view.View>
<android.view.View index="5" text="" class="android.view.View" content-desc="Interest" checkable="false" checked="false" clickable="true" 860]" resource-id="" instance="26"/>
<android.view.View index="6" text="" class="android.view.View" 976]" resource-id="" instance="27">
<android.view.View index="0" text="" class="android.view.View" content-desc="Description" 964]" resource-id="_label-4" instance="28">
<android.view.View index="0" text="" class="android.view.View" content-desc="Description" checkable="false" checked="false" clickable="true" 950]" resource-id="" instance="29"/>
</android.view.View>
<android.widget.EditText NAF="true" index="1" text="" class="android.widget.EditText" checkable="false" checked="false" clickable="true" ,964]" resource-id="" instance="3"/>
</android.view.View>
<android.widget.Button index="7" text="" class="android.widget.Button" content-desc="Submit " checkable="false" checked="false" clickable="true" ,1142]" resource-id="" instance="3"/>
<android.widget.Button index="8" text="" class="android.widget.Button" content-desc="Reset " checkable="false" checked="false" clickable="true" ,1184]" resource-id="" instance="4"/>
</android.view.View>
</android.view.View>
<android.view.View index="7" text="" class="android.view.View" scrollable="true" 184]" resource-id="" instance="30">
<android.view.View index="0" text="" class="android.view.View" content-desc="[ 07:13:10.193 ] Page is loaded." checkable="false" checked="false" clickable="true" 184]" resource-id="" instance="31"/>
<android.view.View index="1" text="" class="android.view.View" content-desc="[ 07:13:10.019 ] Button is clicked." checkable="false" checked="false" clickable="true" 184]" resource-id="" instance="32"/>
</android.view.View>
</android.webkit.WebView>
</android.webkit.WebView>
</android.widget.FrameLayout>
</android.widget.LinearLayout>
<android.view.View index="1" text="" class="android.view.View" resource-id="android:id/statusBarBackground" instance="33"/>
<android.view.View index="2" text="" class="android.view.View" 280]" resource-id="android:id/navigationBarBackground" instance="34"/>
</android.widget.FrameLayout>
</hierarchy>
和代码:
WebElement username = driver.findElementByXPath("//android.webkit.WebView[@content-desc='Sign Up Page']/android.view.View[@index='4']/android.view.View[@index='0']/android.view.View[@index='1']/android.widget.EditText[@index='1']");
username.click();
username.sendKeys("appium_username");
我想将键发送到输入字段到EditText {例如。伍迪}元素。我该怎么做?
以下是我在阅读莱尔评论后写的动作方法:
driver.findElementByXPath("//android.widget.Button[@index='1']").click();
Actions action = new Actions(driver);
action.click(driver.findElement(By.xpath("//android.webkit.WebView[@content-desc='Sign Up Page']/android.view.View[@index='4']/"
+ "android.view.View[@index='0']/android.view.View[@index='1']/android.widget.EditText[@index='1']")));
action.sendKeys("appium_test");
我会遇到以下问题,我并不完全知道发生了什么:org.openqa.selenium.webdriverexception:尚未实现方法(警告:服务器未提供任何stacktrace信息)
从我的观察中,程序通过这些代码线运行后没有显示键盘
尝试清除文本字段,而不是再次发送键
typeText.clear();
typeText.sendKeys(xpath);
//---try using Actions
Actions typeText = new Actions(Driver);
typeText.click(xpath);
typeText.sendKeys(textToSend);
typeText.perform();