脚本如下:
from appium import webdriver
import time
packageName='com.tencent.mm'
appActivity='.ui.LauncherUI'
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'ZX1G2293B6'
desired_caps['appPackage'] = packageName
desired_caps['appActivity'] = appActivity
desired_caps['fullReset'] = 'false'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['fastReset'] = 'false'
desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'}
driver = webdriver.Remote('http://127.0.1.1:4723/wd/hub', desired_caps)
#driver.implicitly_wait(30)
driver.find_element_by_name('我').click()
print (driver.current_context)
driver.find_element_by_name('相册').click()
driver.find_element_by_xpath("//*[contains(@text,'炒股难就用股先生,【Vic66】邀请您一起使用股先生。')]").click()
print (driver.current_context)
driver.find_element_by_xpath("//*[contains(@text,'炒股难就用股先生,【Vic66】邀请您一起使用股先生。')]").click()
print (driver.current_context)
driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
print (driver.current_context)
print (切换ok)
time.sleep(10)
print (driver.page_source)
#点击菜单
driver.find_element_by_id("showMenuIocn").click()
print (driver.current_context)
#点击登录
driver.find_element_by_css_selector("button.login").click()
print (driver.current_context)
driver.find_element_by_css_selector("input.mui-input-clear").clear()
print (driver.current_context)
driver.find_element_by_css_selector("input.mui-input-clear").send_keys("18681378808")
print (driver.current_context)
driver.find_element_by_css_selector("div.mui-input-row.password > input.mui-input-clear").clear()
print (driver.current_context)
driver.find_element_by_css_selector("div.mui-input-row.password > input.mui-input-clear").send_keys("123456")
driver.find_element_by_css_selector("button").click()
driver.switch_to_default_content()
time.sleep(2)
driver.quit()
log 日志如下: