【问题标题】:My test Script is to scroll (dynamic) down drop down list till element found in the list and element will get load once the list get scroll down我的测试脚本是滚动(动态)下拉列表,直到在列表中找到元素,一旦列表向下滚动,元素将被加载
【发布时间】:2020-05-16 20:19:42
【问题描述】:

我正在使用机器人框架。谁能帮我解决下面的代码,我在运行脚本时返回错误。

我的代码是:-

 [Arguments]   ${CustomerName}
    Sleep    4s
    Set Test Variable  ${counter}  24
    log  ${counter}
    FOR  ${counter}  IN RANGE  9999
        log  ${counter}
#        Scroll Element Into View    //div[@tid='customerDropdown_${counter}']
        Execute JavaScript    document.evaluate(\"//div[@class='dropdown-menu w-100 show']/div[${counter}]\",document.body,null,9,null).singleNodeValue.scrollIntoView(true);
        ${present}=  Run Keyword And Return Status    Element Should Be Visible   //div[@title='${CustomerName}']
        log  ${counter}
        Continue For Loop If    ${present} == 'false'  #My Cool Keyword
        Exit For Loop If  ${present}
     END

[参数] ${CustomerName} 睡眠 4s 设置测试变量 ${counter} 24 记录 ${计数器} 价格为 ${counter},范围为 9999 记录 ${counter}

将元素滚动到视图中 //div[@tid='customerDropdown_${counter}']

    Execute JavaScript    document.evaluate(\"//div[@class='dropdown-menu w-100 show']/div[${counter}]\",document.body,null,9,null).singleNodeValue.scrollIntoView(true);
    ${present}=  Run Keyword And Return Status    Element Should Be Visible   //div[@title='${CustomerName}']
    log  ${counter}
    Continue For Loop If    ${present} == 'false'  #My Cool Keyword
    Exit For Loop If  ${present}


 END

出现以下错误:-

JavascriptException:消息:javascript 错误:无法读取 null 的属性“scrollIntoView”

【问题讨论】:

  • JavaScript 行有问题。尝试从非常了解 JS 的人那里获得帮助,因为这与 Robot Framework 没有任何关系。

标签: robotframework


【解决方案1】:

尝试用原生 SeleniumLibrary 关键字替换 Execute Javascript 行:Scroll Element Into View https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Scroll%20Element%20Into%20View

此外,真正的元素可见性不计算在内。我认为预期的条件是检查 webelement 上是否设置了 visibility: hiddendisplay: none。简单地说,也许你甚至不需要滚动来查看元素。 :)

【讨论】:

    猜你喜欢
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多