写了条 case,从 txt 文件读取内容,用 send_keys() 输入到 app 的文本输入框中。可是每个环节好像都正确,最后 case 结果也 ok,就是输入框中没有输入任何内容。请教各位大神这是怎么回事?
def readFile(self,filename):
f = open(filename,"r")
lines = []
while True:
line = f.readline().decode("utf8")
if not line: break
lines.append(line)
f.close()
return "".join(lines)
def test_04_editBody(self):
text = self.readFile("text.txt")
print text
self.driver.find_element_by_xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]").send_keys(text)
self.driver.back()
1. Into the Woods
"Help, A monster!” said Annie.
"Yeah, sure!" said Jack. "A real monster in Frog Creek, Pennsylvania."
"Run, Jack!" said Annie. She ran up the road.
Oh, brother.
This is what he got for spending time with his seven-year-old sister.
Annie loved pretend stuff. But Jack was eight and a half. He liked real things.
"Watch out, Jack! The monster's coming! Race you!"
"No, thanks!” said Jack.
Annie raced alone into the woods. Jack looked at the sky. The sun was about to set.
"Come on, Annie! It's time to go home!"
But Annie had disappeared. Jack waited. No Annie.
"Annie!" he shouted again.
"Jack! Jack! Come here!"
Jack groaned.
(大概 700 个字符)
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.EditText[1] using XPATH with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.EditText, INSTANCE=2]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586"}
info: <-- POST /wd/hub/session/9d9a94a3-aafd-420c-af8c-675e105d4586/element 200 123.966 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586"}
info: --> POST /wd/hub/session/9d9a94a3-aafd-420c-af8c-675e105d4586/element/2/value {"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586","id":"2","value":["1","."," ","I","n","t","o"," ","t","h","e"," ","W","o","o","d","s","\n"," "," "," "," "," ","\n"," "," "," "," "," ","\"","H","e","l","p",","," ","A"," ","m","o","n","s","t","e","r","!","”"," ","s","a","i","d"," ","A","n","n","i","e",".","\n"," "," "," "," "," ","\"","Y","e","a","h",","," ","s","u","r","e","!","\""," ","s","a","i","d"," ","J","a","c","k","."," ","\"","A"," ","r","e","a","l"," ","m","o","n","s","t","e","r"," ","i","n"," ","F","r","o","g"," ","C","r","e","e","k",","," ","P","e","n","n","s","y","l","v","a","n","i","a",".","\"","\n"," "," "," "," "," ","\"","R","u","n",","," ","J","a","c","k","!","\""," ","s","a","i","d"," ","A","n","n","i","e","."," ","S","h","e"," ","r","a","n"," ","u","p"," ","t","h","e"," ","r","o","a","d","."," ","\n"," "," "," "," "," ","O","h",","," ","b","r","o","t","h","e","r",".","\n"," "," "," "," "," ","T","h","i","s"," ","i","s"," ","w","h","a","t"," ","h","e"," ","g","o","
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"2","text":"1. Into the Woods\n \n \"Help, A monster!” said Annie.\n \"Yeah, sure!\" said Jack. \"A real monster in Frog Creek, Pennsylvania.\"\n \"Run, Jack!\" said Annie. She ran up the road. \n Oh, brother.\n This is what he got for spending time with his seven-year-old sister.\n Annie loved pretend stuff. But Jack was eight and a half. He liked real things.\n \"Watch out, Jack! The monster's coming! Race you!\"\n \"No, thanks!” said Jack.\n Annie raced alone into the woods. Jack looked at the sky. The sun was about to set.\n \"Come on, Annie! It's time to go home!\"\n But Annie had disappeared. Jack waited. No Annie.\n \"Annie!\" he shouted again. \n \"Jack! Jack! Come here!\" \n Jack groaned.\n","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"2","text":"1. Into the Woods\n \n \"Help, A monster!” said Annie.\n \"Yeah, sure!\" said Jack. \"A real monster in Frog Creek, Pennsylvania.\"\n \"Run, Jack!\" said Annie. She ran up the road. \n Oh, brother.\n This is what he got for spending time with his seven-year-old sister.\n Annie loved pretend stuff. But Jack was eight and a half. He liked real things.\n \"Watch out, Jack! The monster's coming! Race you!\"\n \"No, thanks!” said Jack.\n Annie raced alone into the woods. Jack looked at the sky. The sun was about to set.\n \"Come on, Annie! It's time to go home!\"\n But Annie had disappeared. Jack waited. No Annie.\n \"Annie!\" he shouted again. \n \"Jack! Jack! Come here!\" \n Jack groaned.\n","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Using element passed in.
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
info: [debug] [UIAUTOMATOR STDOUT] [APPIUM-UIAUTO] [debug] Sending plain text to element: 1. Into the Woods
info: [debug] [UIAUTOMATOR STDOUT] "Help, A monster!” said Annie.
info: [debug] [UIAUTOMATOR STDOUT] "Yeah, sure!" said Jack. "A real monster in Frog Creek, Pennsylvania."
info: [debug] [UIAUTOMATOR STDOUT] "Run, Jack!" said Annie. She ran up the road.
info: [debug] [UIAUTOMATOR STDOUT] Oh, brother.
info: [debug] [UIAUTOMATOR STDOUT] This is what he got for spending time with his seven-year-old sister.
info: [debug] [UIAUTOMATOR STDOUT] Annie loved pretend stuff. But Jack was eight and a half. He liked real things.
info: [debug] [UIAUTOMATOR STDOUT] "Watch out, Jack! The monster's coming! Race you!"
info: [debug] [UIAUTOMATOR STDOUT] "No, thanks!” said Jack.
info: [debug] [UIAUTOMATOR STDOUT] Annie raced alone into the woods. Jack looked at the sky. The sun was about to set.
info: [debug] [UIAUTOMATOR STDOUT] "Come on, Annie! It's time to go home!"
info: [debug] [UIAUTOMATOR STDOUT] But Annie had disappeared. Jack waited. No Annie.
info: [debug] [UIAUTOMATOR STDOUT] "Annie!" he shouted again.
info: [debug] [UIAUTOMATOR STDOUT] "Jack! Jack! Come here!"
info: [debug] [UIAUTOMATOR STDOUT] Jack groaned.
info: [debug] [UIAUTOMATOR STDOUT] [/APPIUM-UIAUTO]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586"}
info: <-- POST /wd/hub/session/9d9a94a3-aafd-420c-af8c-675e105d4586/element/2/value 200 6017.319 ms - 76 {"status":0,"value":true,"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586"}
info: --> POST /wd/hub/session/9d9a94a3-aafd-420c-af8c-675e105d4586/back {"sessionId":"9d9a94a3-aafd-420c-af8c-675e105d4586"}
info: [debug] Pushing command to appium work queue: ["pressBack"]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"pressBack","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: pressBack
实在不懂问题在哪,难道是字符串长度问题?