之前的用例通过 element_by_name 执行的,都可以跑通,但是在更新了 macaca 之后就不行了,通过 name 和 xpath 定位元素都定位不到。有谁也遇到这样的问题吗?
id 定位是可以的

通过 element_by_name 定位元素
self.driver.element_by_name('我的').click()
得到的报错为:

Traceback (most recent call last):
  File "/Users/test/Desktop/317hu_AppTest/Test_case/demo.py", line 68, in test1_peixun
    self.driver.element_by_name('我的').click()
  File "/usr/local/lib/python2.7/site-packages/macaca/util.py", line 77, in find_element
    return self.element(using.value, value)
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriver.py", line 814, in element
    'value': value
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriver.py", line 68, in _execute
    ret.raise_for_status()
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriverresult.py", line 54, in raise_for_status
    raise WebDriverException(error, message, screen, stacktrace)
WebDriverException: 
Error: WebDriverError.INVALID_SELECTOR
Message: None

log 如下

>> responseHandler.js:11:12 [master] pid:8656 Recieve HTTP Request from Client[2017-05-12 13:31:54]: method: POST url: /wd/hub/session/628fa519-55d4-4d35-93b4-444e671638ca/element, jsonBody: {"using":"name","value":"我的"}
>> proxy.js:54:14 [master] pid:8656 Proxy: /wd/hub/session/628fa519-55d4-4d35-93b4-444e671638ca/element:POST to http://127.0.0.1:9001/wd/hub/session/628fa519-55d4-4d35-93b4-444e671638ca/element:POST with body: {"using":"name","value":"我的"}
>> proxy.js:82:20 [master] pid:8656 Got response with status 200: {"status":32,"value":"Argument was an invalid selector (e.g. XPath/CSS).","sessionId":null}
>> session.js:107:14 [master] pid:8656 Send HTTP Respone to Client[2017-05-12 13:31:54]: {"status":32,"value":"\"Argument was an invalid selector (e.g. XPath/CSS).\"","sessionId":null}
>> responseHandler.js:11:12 [master] pid:8656 Recieve HTTP Request from Client[2017-05-12 13:31:54]: method: DELETE url: /wd/hub/session/628fa519-55d4-4d35-93b4-444e671638ca, jsonBody: {}
>> session.js:80:12 [master] pid:8656 Delete session, sessionId: 628fa519-55d4-4d35-93b4-444e671638ca
>> responseHandler.js:47:14 [master] pid:8656 Send HTTP Respone to Client[2017-05-12 13:31:54]: {"sessionId":"628fa519-55d4-4d35-93b4-444e671638ca","status":0}

通过 element_by_xpath
elf.driver.element_by_xpath('//*[@text="我的"]').click()

得到的报错结果为

Traceback (most recent call last):
  File "/Users/test/Desktop/317hu_AppTest/Test_case/demo.py", line 69, in test1_peixun
    self.driver.element_by_xpath('//*[@text="我的"]').click()
  File "/usr/local/lib/python2.7/site-packages/macaca/util.py", line 77, in find_element
    return self.element(using.value, value)
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriver.py", line 814, in element
    'value': value
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriver.py", line 68, in _execute
    ret.raise_for_status()
  File "/usr/local/lib/python2.7/site-packages/macaca/webdriverresult.py", line 54, in raise_for_status
    raise WebDriverException(error, message, screen, stacktrace)
WebDriverException: 
Error: WebDriverError.INVALID_SELECTOR
Message: None

通 element_by_id 可正常执行
self.driver.element_by_id('id/home_mine_layout').click()


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