繁体   English   中英

机器人框架中的搜索上下文

[英]Search context in robot framework

在 selenium Java 中,我们可以通过findElement(locator1).findElement(locator2)找到一个元素
DefaultElementLocatorFactory locatorFactory = new DefaultElementLocatorFactory(getElement()); PageFactory.initElements(locatorFactory, this); Q1。 我们如何在机器人框架中实现相同的目标? Q2。 我们如何在 python 中实现相同的目标?

https://github.com/robotframework/SeleniumLibrary/issues/672

没有内置 function,但您可以使用:

创建关键字

  Get child element

它需要两个参数 parent(Webelement) 和 child(Xpath) 在父项中搜索子项。

  Get child element    ${parent}    ./h3

假设父 xpath 为: //ul[@id="top_menu"] ,上面的代码将搜索相等的 xpath //ul[@id="top_menu"]/./h3注意上下文是父而不是根

所以这将等于 xpath

*** Test Cases ***
Google Search
    [Tags]    you    probably    do    not    have    this    many    tags    in    real    life
    Wait Until Element Is Visible  CSS=[id="introduction-container"]
    ${parent}=    Get webelement    xpath=//*[@id="introduction-container"]
    ${result}=    Get child element    ${parent}    ./h3   
        
    
*** Keywords ***
Get child element 
    [Arguments]    ${parent}   ${child} 
    ${child}=    Execute Javascript    return window.document.evaluate( arguments[1], arguments[0], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;     ARGUMENTS    ${parent}    ${child}
    [Return]    ${child}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM