我现在想测试一款 APP,该 App 包含一个登陆的界面以及登陆后的页面,如何不用 By.name() 这个方法 ,能够定位控件。我曾经想过使用 XPath,但问题在于,其登录前与登陆后 XPath 的开头均为//window[1] 。无法确定是哪一个的控件,大神帮帮忙吧。

5:30 PM
已经能够获取指定控件(Textfield),但是传值失效。
java 代码:

List<WebElement> elems = wd.findElements(By.tagName("UIASecureTextField"));
    for(WebElement e:elems){
  e.sendKeys("123456");}   //能够获取控件 ,但是传值失效

log:


info: Welcome to Appium v0.12.3

info: Appium REST http interface listener started on 127.0.0.1:4723
   info  - socket.io started

info: Not spawning instruments force-quit watcher since it only works on 10.9 and you have 10.8.5

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Appium request initiated at /wd/hub/status

GET /wd/hub/status 200 9ms - 144b

debug: Request received with params: {}

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Request received with params: {}

GET /wd/hub/status 200 2ms - 144b

debug: Appium request initiated at /wd/hub/session

info: Using local app from desiredCaps: /Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app

debug: Request received with params: {"desiredCapabilities":{"platform":"Mac","app":"/Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app","browserName":"iOS","version":"6.1"}}

info: Creating new appium session e61d6443-50dd-4720-bb70-a42546709b86
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock

info: Parsed app Localizable.strings

info: Killing the simulator process

debug: Launching device: iPhone (3.5-inch)

info: Parsed app Info.plist

info: Wrote new app Info.plist with device type

info: Starting iOS 7.* simulator log capture

debug: No device id or app, not installing to real device.

debug: Creating instruments

info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments

info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/iwd/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/iwd"}
info: And launch timeout: 90000ms

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}},"sessionId":"e61d6443-50dd-4720-bb70-a42546709b86"}

debug: Request received with params: {}

GET /wd/hub/status 200 1ms - 199b

info: [INST STDERR] 2013-12-20 11:24:57.972 ScriptAgent[16241:2e07] CLTilesManagerClient: initialize, sSharedTilesManagerClient


info: [INST STDERR] 2013-12-20 11:24:57.972 ScriptAgent[16241:2e07] CLTilesManagerClient: init
2013-12-20 11:24:57.973 ScriptAgent[16241:2e07] CLTilesManagerClient: reconnecting, 0x96705e0


info: [INSTSERVER] Instruments is ready to receive commands

debug: Sending command to instruments: au.bundleId()

info: Instruments launched. Starting poll loop for new commands.
info: Pushing command to appium work queue: "au.bundleId()"
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.bundleId()

info: [INSTSERVER] Socket data received (68 bytes)

debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"com.accela.inspector"}
info: Bundle ID for open app is com.accela.inspector
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data received (56 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId e61d6443-50dd-4720-bb70-a42546709b86
POST /wd/hub/session 303 87390ms - 9b

debug: Appium request initiated at /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86

info: Responding to client with success: {"status":0,"value":{"version":"7.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"iOS","platform":"Mac","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"app":"/Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app"},"sessionId":"e61d6443-50dd-4720-bb70-a42546709b86"}

debug: Request received with params: {}

GET /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86 200 1ms - 470b

debug: Appium request initiated at /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/timeouts/implicit_wait

info: Set iOS implicit wait to 60000ms

debug: Request received with params: {"ms":60000}

info: Responding to client with success: {"status":0,"value":null,"sessionId":"e61d6443-50dd-4720-bb70-a42546709b86"}
POST /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/timeouts/implicit_wait 200 2ms - 89b
info: Pushing command to appium work queue: "au.getElementsByType('UIATextField')"
info: [INSTSERVER] Sending command to instruments: au.getElementsByType('UIATextField')

debug: Appium request initiated at /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/elements
debug: Request received with params: {"using":"tag name","value":"UIATextField"}
debug: Sending command to instruments: au.getElementsByType('UIATextField')

info: [INSTSERVER] Socket data received (79 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}]}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}],"sessionId":"e61d6443-50dd-4720-bb70-a42546709b86"}
POST /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/elements 200 1375ms - 157b

debug: Appium request initiated at /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/element/0/value

info: Pushing command to appium work queue: "au.getElement('0').setValueByType('123456')"

debug: Request received with params: {"id":"0","value":["123456"]}
debug: Sending command to instruments: au.getElement('0').setValueByType('123456')

info: [INSTSERVER] Sending command to instruments: au.getElement('0').setValueByType('123456')

info: [INSTSERVER] Socket data received (202 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":17,"value":"Unexpected error in -[UIATextField_0xa3a67d0 setValue:], /SourceCache/UIAutomation_Sim/UIAutomation-365/Framework/UIAElement.m line 1061, kAXErrorFailure"}
info: Responding to client with error: {"status":17,"value":{"message":"An error occurred while executing user supplied JavaScript.","origValue":"Unexpected error in -[UIATextField_0xa3a67d0 setValue:], /SourceCache/UIAutomation_Sim/UIAutomation-365/Framework/UIAElement.m line 1061, kAXErrorFailure"},"sessionId":"e61d6443-50dd-4720-bb70-a42546709b86"}
POST /wd/hub/session/e61d6443-50dd-4720-bb70-a42546709b86/element/0/value 500 201ms - 342b







2013.12.20  2:02PM  



info: Welcome to Appium v0.12.3

info: Appium REST http interface listener started on 127.0.0.1:4723
   info  - socket.io started
info: Not spawning instruments force-quit watcher since it only works on 10.9 and you have 10.8.5

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

GET /wd/hub/status 200 7ms - 144b

debug: Appium request initiated at /wd/hub/status

debug: Request received with params: {}

debug: Appium request initiated at /wd/hub/session

debug: Request received with params: {"desiredCapabilities":{"platform":"Mac","app":"/Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app","browserName":"iOS","version":"6.1"}}

info: Using local app from desiredCaps: /Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app

info: Creating new appium session 0b708449-5477-424b-ba90-15f26df3cf66
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock

info: Parsed app Localizable.strings

info: Killing the simulator process

debug: Launching device: iPhone (3.5-inch)

info: Parsed app Info.plist

debug: No device id or app, not installing to real device.
debug: Creating instruments

info: Wrote new app Info.plist with device type
info: Starting iOS 7.* simulator log capture

info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/iwd/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/iwd"}
info: And launch timeout: 90000ms

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}},"sessionId":"0b708449-5477-424b-ba90-15f26df3cf66"}
GET /wd/hub/status 200 2ms - 199b

debug: Request received with params: {}

info: [INST STDERR] 2013-12-20 14:01:17.722 ScriptAgent[1139:2e07] CLTilesManagerClient: initialize, sSharedTilesManagerClient


info: [INST STDERR] 2013-12-20 14:01:17.725 ScriptAgent[1139:2e07] CLTilesManagerClient: init
2013-12-20 14:01:17.725 ScriptAgent[1139:2e07] CLTilesManagerClient: reconnecting, 0xa13a400


info: [INSTSERVER] Instruments is ready to receive commands

debug: Sending command to instruments: au.bundleId()

info: Instruments launched. Starting poll loop for new commands.
info: Pushing command to appium work queue: "au.bundleId()"

info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.bundleId()

info: [INSTSERVER] Socket data received (68 bytes)

debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"com.accela.inspector"}
info: Bundle ID for open app is com.accela.inspector
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data received (56 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId 0b708449-5477-424b-ba90-15f26df3cf66

POST /wd/hub/session 303 10873ms - 9b

debug: Appium request initiated at /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66

info: Responding to client with success: {"status":0,"value":{"version":"7.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"iOS","platform":"Mac","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"app":"/Users/DEV/Library/Developer/Xcode/DerivedData/Inspector-dldvhbusyfhhaifiqsmclsjgisxy/Build/Products/Debug-iphonesimulator/Inspector.app"},"sessionId":"0b708449-5477-424b-ba90-15f26df3cf66"}
GET /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66 200 2ms - 470b

debug: Request received with params: {}

debug: Appium request initiated at /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/timeouts/implicit_wait

info: Set iOS implicit wait to 60000ms

debug: Request received with params: {"ms":60000}
debug: Appium request initiated at /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/elements
debug: Request received with params: {"using":"tag name","value":"UIATextField"}

info: Responding to client with success: {"status":0,"value":null,"sessionId":"0b708449-5477-424b-ba90-15f26df3cf66"}
POST /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/timeouts/implicit_wait 200 3ms - 89b
info: Pushing command to appium work queue: "au.getElementsByType('UIATextField')"
info: [INSTSERVER] Sending command to instruments: au.getElementsByType('UIATextField')

debug: Sending command to instruments: au.getElementsByType('UIATextField')

info: [INSTSERVER] Socket data received (79 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}]}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}],"sessionId":"0b708449-5477-424b-ba90-15f26df3cf66"}
POST /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/elements 200 570ms - 157b

debug: Appium request initiated at /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/execute

info: Pushing command to appium work queue: "au.getElement('0').setValue('123456')"
info: [INSTSERVER] Sending command to instruments: au.getElement('0').setValue('123456')

debug: Request received with params: {"args":[{"element":"0","value":"123456"}],"script":"mobile: setValue"}
debug: Sending command to instruments: au.getElement('0').setValue('123456')

info: [INSTSERVER] Socket data received (202 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":17,"value":"Unexpected error in -[UIATextField_0xa384660 setValue:], /SourceCache/UIAutomation_Sim/UIAutomation-365/Framework/UIAElement.m line 1061, kAXErrorFailure"}
info: Responding to client with error: {"status":17,"value":{"message":"An error occurred while executing user supplied JavaScript.","origValue":"Unexpected error in -[UIATextField_0xa384660 setValue:], /SourceCache/UIAutomation_Sim/UIAutomation-365/Framework/UIAElement.m line 1061, kAXErrorFailure"},"sessionId":"0b708449-5477-424b-ba90-15f26df3cf66"}
POST /wd/hub/session/0b708449-5477-424b-ba90-15f26df3cf66/execute 500 216ms - 342b



↙↙↙阅读原文可查看相关链接,并与作者交流