Appium无法点击元素

时间:2017-03-09 15:12:01

标签: android react-native appium python-appium

Appium和react-native之间的通信存在问题。我在android(现在)

上试了一下

这是我想要测试的组件:

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
} from 'react-native';

export default class HomeScreen extends Component {
  static navigationOptions = {
    title: 'myAwesomeApp',
  };
  render() {
    const { navigate } = this.props.navigation;
    return (
      <View style={styles.container}>
        <Text onPress={() => navigate('Registration')}>
          BleedRegistration
        </Text>
        <Text onPress={() => navigate('Log')}>
          MedicationLog
        </Text>
        <TouchableHighlight id={'XXXX1'} accessibilityLabel={'XXXX'} onPress={() => navigate('Reporting')}>
          <Text id={'XXXX2'} accessibilityLabel={'XXXX3'}>
            Reports1
          </Text>
        </TouchableHighlight>
      </View>
    );
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
    alignItems: 'center',
    justifyContent: 'space-around',
  },
});

这是我的测试类:

import os
import unittest
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction

class AppiumTest(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'app': os.path.expanduser('./android/app/build/outputs/apk/app-debug.apk'),
                'platformName': 'Android',
                'deviceName': 'Nexus 5 API 25',
        })

    def tearDown(self):
        self.driver.quit()


class ElementsExistTests(AppiumTest):

    def test_elements(self):
        textBleedRegistration = self.driver.find_elements_by_accessibility_id("BleedRegistration")
        textMedicationLog = self.driver.find_elements_by_accessibility_id("MedicationLog")
        textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
        myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
        self.assertIsNotNone(textRegistration)
        self.assertIsNotNone(textLog)
        self.assertIsNotNone(textReports1)
        self.assertIsNotNone(myTouchableHighligh)





class ClickTests(AppiumTest):

    def test_reports(self):
        myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
        #textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
        action = TouchAction(self.driver)
        action.press(myTouchableHighligh).perform()
        self.assertIsNotNone(myTouchableHighligh)

这是appium服务器中的错误日志:

self = <test.ClickTests testMethod=test_reports>

    def test_reports(self):
        myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
        #textReports1 = self.driver.find_elements_by_accessibility_id("Reports1")
        action = TouchAction(self.driver)
>       action.press(myTouchableHighligh).perform()

test.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/site-packages/appium/webdriver/common/touch_action.py:53: in press
    self._add_action('press', self._get_opts(el, x, y))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <appium.webdriver.common.touch_action.TouchAction object at 0x10d698c90>, element = [], x = None, y = None, duration = None

    def _get_opts(self, element, x, y, duration = None):
        opts = {}
        if element is not None:
>           opts['element'] = element.id
E           AttributeError: 'list' object has no attribute 'id'

/usr/local/lib/python2.7/site-packages/appium/webdriver/common/touch_action.py:118: AttributeError

第一次测试ElementsExistTests已通过...确定,在第二次测试中,我想点击<Text><TouchableHighlight>之一,但我不能,因为AttributeError: 'list' object has no attribute 'id' < / p>

我尝试了简单的方法(作为一些教程)并像这样写

def test_reports(self):
    myTouchableHighligh = self.driver.find_elements_by_accessibility_id("XXXX1")
    myTouchableHighligh.click()
    self.assertIsNotNone(myTouchableHighligh)

并且AttributeError: 'list' object has no attribute 'click'

返回myTouchableHighligh.tap()相同的错误

你能帮帮我,告诉我出了什么问题吗?

0 个答案:

没有答案