请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

用ui_automator 看到有webview,但是在代码中打印只有native,是怎么回事

代码运行成功,和老师的一样

#!/usr/bin/env python
#coding:utf-8

import time
from appium import webdriver

def get_driver():
   capabilities = {
       "platformName": "Android",
       "deviceName": "127.0.0.1:62001",
       # "deviceName": "836f314e4d56544c",
       "app": r"C:\Users\YUNEEC\Desktop\mukewang_6220.apk",

       # "appWaitActivity": "cn.com.open.mooc.index.splash.GuideActivity"
       # "noReset": True
   }

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


#获取屏幕的宽高

def get_size():
   size = driver.get_window_size()
   # print size
   width = size['width']
   height = size['height']
   return width,height

#向左滑动
def swipe_left():
   x1 = get_size()[0]/10*9
   y1 = get_size()[1]/2
   x = get_size()[0]/10
   driver.swipe(x1,y1,x,y1,2000)



#向右边滑动
def swipe_right():
   x1 = get_size()[0]/10
   y1 = get_size()[1]/2
   x = get_size()[0]/10*9
   driver.swipe(x1,y1,x,y1,2000)

#向上滑动
def swipe_up():
   #[100,200]direction
   x1 = get_size()[0]/2
   y1 = get_size()[1]/10*9
   y = get_size()[1]/10
   driver.swipe(x1,y1,x1,y,1000)

#向下滑动
def swipe_down():
   #[100,200]
   x1 = get_size()[0]/2
   y1 = get_size()[1]/10
   y = get_size()[1]/10*9
   driver.swipe(x1,y1,x1,y)

def swipe_on(direction):
   if direction == 'up':
       swipe_up()
   elif direction == 'down':
       swipe_down()
   elif direction =='left':
       swipe_left()
   else:
       swipe_right()


def go_login():
   time.sleep(2)
   elements = driver.find_elements_by_id('android:id/text1')
   elements[3].click()
   time.sleep(2)
   elements = driver.find_elements_by_class_name("android.widget.TextView")
   time.sleep(2)
   elements[1].click()
   time.sleep(2)
   element = driver.find_element_by_id("cn.com.open.mooc:id/tv_go_login")
   element.click()
   time.sleep(2)
   driver.find_element_by_id("cn.com.open.mooc:id/account_edit").send_keys("18721246326")
   time.sleep(1)
   driver.find_element_by_id("cn.com.open.mooc:id/password_edit").send_keys("123456")
   time.sleep(1)
   driver.find_element_by_id("cn.com.open.mooc:id/login").click()
   time.sleep(1)


def get_web_view():
   webview = driver.contexts
   print webview

   # print(len(elements))
   # for i in elements:
   #     time.sleep(5)
   #     print i
   #     i.click()



driver = get_driver()
time.sleep(5)
swipe_on('left')
time.sleep(1)
swipe_on('left')
time.sleep(1)
swipe_on('left')
time.sleep(1)
swipe_on("up")
time.sleep(1)

go_login()
time.sleep(10)
get_web_view()

time.sleep(10)
driver.quit()


-----------------------------------------------------------------------------

运行结果:[u'NATIVE_APP']


正在回答 回答被采纳积分+3

4回答

提问者 慕后端4292073 2018-07-31 11:38:40



请老师看下,是哪里错误

以下是剩余的appium log :

https://img1.sycdn.imooc.com//szimg/5b5fdc2b00012add17010899.jpghttps://img1.sycdn.imooc.com//szimg/5b5fdc2e0001947817040410.jpg

0 回复 有任何疑惑可以回复我~
提问者 慕后端4292073 2018-07-31 11:37:38

android 版本:4.4.2

模拟器版本: 6.2.0.3

https://img1.sycdn.imooc.com//szimg/5b5fdbd50001db0911740996.jpghttps://img1.sycdn.imooc.com//szimg/5b5fdbd800010aa615210899.jpghttps://img1.sycdn.imooc.com//szimg/5b5fdbdf0001061516920895.jpg

0 回复 有任何疑惑可以回复我~
提问者 慕后端4292073 2018-07-27 13:23:39

我加了sleep,手工操作到了有h5的界面,等待代码执行的!
老师你最后一句啥意思,是说虚拟手机有问题,只有实体手机才可以检测到h5页面吗?

0 回复 有任何疑惑可以回复我~
  • 你好,不是的。这个虚拟机不一定,你看一下你appium的日志然后你发一下你模拟器版本及android的版本。这个不是所有的机器都行。
    回复 有任何疑惑可以回复我~ 2018-07-28 22:08:09
  • 提问者 慕后端4292073 回复 Mushishi #2
    老师,可否抽时间看下我这个问题
    回复 有任何疑惑可以回复我~ 2018-08-02 09:35:52
Mushishi 2018-07-27 13:05:22

你需要走到H5页面然后再通过这个方法去打印才可以。但是还有个问题就是不是所有实体机器可以打印。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号