robot框架中的java搜索上下文

sh7euo9m  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(380)

在seleniumjava中,我们可以通过 findElement(locator1).findElement(locator2) 我们也能做到 DefaultElementLocatorFactory locatorFactory = new DefaultElementLocatorFactory(getElement()); PageFactory.initElements(locatorFactory, this); 问题1。如何在机器人框架中实现同样的功能?问题2。如何在python中实现相同的功能?

cpjpxq1n

cpjpxq1n1#

https://github.com/robotframework/seleniumlibrary/issues/672
没有内置函数,但可以使用:
创建关键字

Get child element

它需要两个参数parent(webelement)和child(xpath)来搜索父级中的子级。

Get child element    ${parent}    ./h3

假设父xpath为: //ul[@id="top_menu"] ,上面的代码将搜索相等的xpath //ul[@id="top_menu"]/./h3 注意taht上下文是父上下文而不是根上下文
所以这将等同于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}

相关问题