WebDriverException:消息:'/?/?/ button [@ accessiblename ='Close']'有一个无效的令牌

时间:2017-01-23 16:39:40

标签: selenium xpath robotframework

我有测试win32 app的简单测试用例。通过Selenium Library我试图关闭应用程序。重点是使用Xpath。 这是机器人的档案:

*** Settings ***
Library Process

Suite Teardown    Terminate All Processes    kill=True

*** TestCases ***
StartGui
    start_gui
    Click Element   id=btnManualRequest
    Click Element   xpath=/form[@wpfnative='True' and @title='MEV 2.7.60' and @processname='MEV.Gui']/?/?/button[@accessiblename='Close']

*** Keywords ***
start_gui
    Start process   C:\\test\\robot\\Winium.Desktop.Driver\\Winium.Desktop.Driver.exe   shell=no  alias=first
    Import Library  Selenium2Library
    ${winium_host}= Set Variable    localhost
    ${winium_port}= Set Variable    9999
    ${capabilities}=    Create Dictionary   app=C:\\test\\app\\MEV.Gui.exe  
    Create Webdriver    Remote  command_executor=http://${winium_host}:${winium_port}   desired_capabilities=${capabilities}
    sleep   8

我收到了这条消息:

WebDriverException: Message: '/form[@wpfnative='True' and @title='MEV 2.7.60' and @processname='MEV.Gui']/?/?/button[@accessiblename='Close']' has an invalid token.

也许我失明了,但我不明白哪里出错了,为什么我不能用xpath到达元素。

更新: 只需使用calc.exe创建非常简单的测试用例:

*** Settings ***
Library Process
Library Selenium2Library

Suite Teardown  Terminate All Processes    kill=True

*** TestCases ***
calcStartStop
Start process   C:\\test\\robot\\Winium.Desktop.Driver\\Winium.Desktop.Driver.exe   shell=no  alias=first
    ${winium_host}=    Set Variable    localhost
    ${winium_port}=    Set Variable    9999
    ${capabilities}=    Create Dictionary    app=C:\\Windows\\System32\\calc.exe
    Create Webdriver    Remote    command_executor=http://${winium_host}:${winium_port}    desired_capabilities=${capabilities}
    Click Element   xpath=//form[@processname='calc' and @class='CalcFrame' and @instance='1']/?/?/button[@accessiblename='Close']

答案相同:

calcStartStop                                                         | FAIL |
WebDriverException: Message: '//form[@processname='calc' and @class='CalcFrame
and @instance='1']/?/?/button[@accessiblename='Close']' has an invalid token.

我认为问题是我错了xpath。有人知道如何为win32 app找到正确的xpath吗?

1 个答案:

答案 0 :(得分:0)

?不是XPath语法的一部分,任何不在字符串中的?都会导致语法错误。

如果检查器工具返回包含?作为轴步骤的XPath表达式,则应考虑使用其他程序。如果您打算使用通配符作为元素名称,请使用*,正如评论者已经指出的那样。

或者,您确定路径不应该是RanoreXPath表达式吗? ?可能是XPath和RanoreXPath之间的差异之一。