首页 文章

在Robot Framework中获取xpath的节点名称

提问于
浏览
0

无法找到我的问题的解决方案 . 我有节点要识别,我的意思是 - 我必须得到以下情况的节点名称:

<content-scope scope-data="scopeData">
  <link-group data="scopeData[0]">
  <text-img data="scopeData[1]">
</content-scope>

当我使用以下语法(FirePath,直接从浏览器)

name((//content-scope[@scope-data='scopeData']/*)[1])

要么

name((//content-scope[@scope-data='scopeData']/*)[2])

然后我得到节点名称(link-group和text-img) .

在机器人框架中,它不适用于关键字Get Text或Get Value . 我收到消息:“InvalidSelectorException:Message:invalid selector:无法找到带有xpath表达式名称的元素((// content-scope [@ scope-data ='scopeData'] / *)[1])因为以下内容error:TypeError:无法在'Document'上执行'evaluate':结果不是节点集,因此无法转换为所需类型 . (会话信息:chrome = 44.0.2403.157)“

这是一个RF代码(简化):

*** Settings ***
Documentation     Cards keywords library
Library           ExtendedSelenium2Library
Library           Collections

*** Variables ***
${cardsXpathNameStart}    xpath=name(//content-scope[@scope-data='scopeData']/*)[
${index}          1

*** Test Cases ***
Getting Card Xpath Type
    Get Card Xpath Type

*** Keywords ***
Get Card Xpath Type
    : FOR    ${index}    IN RANGE    1    2
    \    ${cardXpathType}    Get Text    ${cardsXpathNameStart}${index}]
    \    Log    ${cardXpathType}

如何构建由RF解释的正确xpath或应该使用哪个关键字?

1 回答

  • 1

    我有来自WarBar的解决方案(google groups,robotframework-users):

    RF代码:

    Open Browser    file:///D:/temp/rf/a.html   
    ${elements} Get Webelements //content-scope[@scope-data='scopeData']/*
    log ${elements[0].tag_name}
    

    给出结果:

    20150826 10:37:37.551 :  INFO : Creating an instance of the Firefox WebDriver
    20150826 10:37:40.326 :  INFO : Opening url 'file:///D:/temp/rf/a.html'
    20150826 10:37:40.474 :  INFO : ${elements} = [<selenium.webdriver.remote.webelement.WebElement object at 0x03FCBA10>]
    20150826 10:37:40.485 :  INFO : link-group
    

相关问题