Appium 求助大神一个问题,关于 appium 中截图的,用同样的代码,在不同的区域截图,为什么有的能截成功,有的又不行

枫叶 · August 24, 2017 · Last by 枫叶 replied at August 28, 2017 · 1202 hits

用同样的代码,在不同的区域截图,为什么有的能截成功,有的又不行呢,求大神看下,是不是哪里有问题,指点一二

sleep(10)
        driver.find_element_by_name("**").click()
        sleep(2)
        print 555#没打印出555,不知道为什么,但是代码已经运行到这之后了
        driver.get_screenshot_as_file(u"E:\html\screenshot\%s.png" % datetime.datetime.now().strftime("%Y_%m_%d.%H_%M_%S"))#能正常截图
        sleep(1)
        driver.find_element_by_name("**").click()
        sleep(10)
        driver.find_element_by_id('com.dayhr:id/top_right_img').click()
        sleep(10)
        print 1
        driver.get_screenshot_as_file(u"E:\html\screenshot\%s.png" % datetime.datetime.now().strftime("%Y_%m_%d.%H_%M_%S"))#能正常截图
        webview = driver.contexts[-1]

        driver.switch_to.context(webview)
        self.driver = driver


    def test(self):
        self.driver.find_element_by_xpath('//*[@id="workflow_mobile_create_content"]/ul/li[1]/div/div[1]').click()
        sleep(10)
        self.driver.find_element_by_xpath('//*[@id="workflowFormPreview"]/div/div/div[2]/textarea').send_keys(u"测试111111111")
        sleep(5)
        self.driver.find_element_by_xpath('//*[@id="form_btn_send"]/button').click()
        sleep(3)
        print 1
        self.driver.get_screenshot_as_file(u"E:\html\screenshot\%s.png" % datetime.datetime.now().strftime("%Y_%m_%d.%H_%M_%S"))#截图失败
        print 2
        sleep(2)
共收到 2 条回复 时间 点赞

driver.switch_to_default_content() 切换回来再截图试试

枫叶 #2 · August 28, 2017 Author

恩恩,今天试了下,可以截图了,话说这个为什么在 webview 中不能执行截图操作呢,这个 driver.get_screenshot_as_file()不是本来就是在 web 页面中执行的截图操作吗

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up