遇到了跟您一样的问题,请问解决了吗?
#-*- coding:utf-8 -*-
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('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")
#点击button
el.click()
#
textfields = driver.find_elements_by_tag_name("textfield")
#添加
textfields[0].send_keys("GENGJIKUN")
#添加
textfields[1].send_keys("15201558593")
#添加
textfields[2].send_keys("jikunshishen@163.com")
#点击保存
driver.find_element_by_name("Save").click()
#退出
driver.quit()
能帮我添下注释么?
#12 楼 @lihuazhang 我就是太粗心了~ 谢谢了哈
#-*- coding:utf-8 -*-
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('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")
textfields[0].send_keys("My Name")
textfields[2].send_keys("someone@somewhere.com")
driver.find_element_by_name("Save").click()
driver.quit()
成功了~谢谢!我太粗心了~
#-*- coding:utf-8 -*-
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:\appium-master\sample-code\apps\ContactManager\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")
textfields[0].send_keys("My Name")
textfields[2].send_keys("someone@somewhere.com")
driver.find_element_by_name("Save").click()
driver.quit()
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:\test\ContactManager.apk')
desired_caps['app-package'] = 'com.example.android.contactmanager'
desired_caps['app-activity'] = '.ContactManager'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
el = driver.find_element_by_name("Add Contact")
el.click()
textfields = driver.find_elements_by_tag_name("textfield")
textfields[0].send_keys("My Name")
textfields[2].send_keys("someone@somewhere.com")
driver.find_element_by_name("Save").click()
driver.quit()
根据你的教程做的~
不知道怎么弄了~
import os
from selenium import webdriver
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:\test\ContactManager.apk')
desired_caps['app-package'] = 'com.example.android.contactmanager'
desired_caps['app-activity'] = '.ContactManager'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
el = driver.find_element_by_name("Add Contact")
el.click()
textfields = driver.find_elements_by_tag_name("textfield")
textfields[0].send_keys("My Name")
textfields[2].send_keys("someone@somewhere.com")
driver.find_element_by_name("Save").click()
driver.quit()
Traceback (most recent call last):
File "C:\android_contact.py", line 17, in
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 71, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 113, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 164, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u"A new session could not be created. (Original error: Bad app: C:\C:\test\ContactManager.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat 'C:\C:\test\ContactManager.apk')"