我的测试代码如下。
import unittest
from selenium import webdriver

class Test(unittest.TestCase):
desired_caps = {}
def setUp(self):

self.desired_caps['device'] = 'Android'
self.desired_caps['browserName'] = ''
self.desired_caps['version'] = '4.2'
self.desired_caps['app'] = '/Users/apple/Downloads/spondroid-debug-unaligned.apk'
self.desired_caps['app-package'] = 'com.spond.spond'
self.desired_caps['app-activity'] = '.WelcomeActivity'

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

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

def testLogin(self):
driver = self.driver
loginButton =driver.find_element_by_name('Log in')
#to check if we can get the tag name through method WebElement.tag_name()
print('loginButton.tag_name():'+loginButton.tag_name())# print(type(loginButton.id()))
print(loginButton.id())
if loginButton.is_enabled():

print("loginButton.is_enabled():true")
else:
print('loginButton.is_enabled():false')
if loginButton.is_displayed():
print('loginButton.is_displayed():true')
else:
print('loginButton.is_displayed():false')
print('loginButton.text:'+loginButton.text)

if name == "main":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()

运行时报错:

======================================================================

ERROR: testLogin (android_login.Test)

Traceback (most recent call last):
File "/Users/apple/Documents/workspace/autoSpond/src/python/android_login.py", line 37, in testLogin
print('loginButton.tag_name():'+loginButton.tag_name())# print(type(loginButton.id()))
TypeError: 'unicode' object is not callable


Ran 1 test in 17.130s

FAILED (errors=1)

请各位大侠帮忙看看,这个问题怎么解决啊。先谢谢啦!


↙↙↙阅读原文可查看相关链接,并与作者交流