楼主你好!用代码编译后,textfields[0].send_keys("My Name") 报 index:error,请问怎么解决呀?试过很多方法了,自行解决不了,谢谢

import os

from selenium import webdriver

Returns abs path relative to this file and not cwd

PATH = lambda p: os.path.abspath(

os.path.join(os.path.dirname(file), p)

)

desired_caps = {}

desired_caps['device'] = 'Android'

desired_caps['browserName'] = ''

desired_caps['version'] = '4.2.2'

desired_caps['app'] = PATH('C:\Users\Succi\Desktop\ContactManager.apk')

desired_caps['app-package'] = 'com.example.android.contactmanager'

desired_caps['app-activity'] = '.ContactManager'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

el = driver.find_element_by_name("Add Contact")

el.click()

textfields = driver.find_elements_by_tag_name("textfield")

print("debug:",textfields)#input list

textfields[0].send_keys("My Name")

textfields[2].send_keys("someone@somewhere.com")

driver.find_element_by_name("Save").click()

driver.quit()

错误信息:

('debug:', [])

Traceback (most recent call last):

File "android_contact.py", line 24, in

textfields[1].send_keys("My Name")

IndexError: list index out of range

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐