extjs 在robotframework selenium2库中保存javascript的返回值,返回值为0

owfi6suc  于 2022-11-05  发布在  Java
关注(0)|答案(1)|浏览(140)

我想做的是单击页面上的所有链接并关闭即将出现的选项卡。这些选项卡位于:

<ul>
   <li>
      <a href=#>random text</a>
   </li>
   <li>...

由于有许多链接点击,我尝试了类似的东西:

Click All Links
    Set Global Variable    ${i}    1
    ${elementCount}=    Execute Javascript    return document.querySelectorAll('a').length
    FOR    ${i}   IN RANGE    ${elementCount}
        Execute Javascript    document.getElementsByTagName('a')[i].click();
        Run Keyword and Ignore Error    Delete Tab
        Exit For Loop If    ${i} == elementCount
    END
    Log    Exited

Delete Tab
    Sleep    ${Delay_short}
    ${title_var}    Get Window Titles
    Select Window    title=${title_var}[1]
    Close Window

但是我不能超过第一个返回长度,因为${elementCount}总是显示为值0:

Executing JavaScript:
return document.querySelectorAll('a').length
Without any arguments.
20210104 10:20:26.687 :  INFO : ${elementCount} = 0

任何进一步的帮助将不胜感激。

xzabzqsa

xzabzqsa1#

所以问题不在于代码,而不是被查看的页面-它给了一个401,所以我有其他的东西来挑战第一。
由于下半部分不工作,以及,这里什么工作对我来说:

Click Àll Links
    Set Variable    ${i}    0
    ${elementCount}=    Execute Javascript    return document.querySelectorAll('a').length-1
    FOR    ${i}   IN RANGE    ${elementCount}
        Execute Javascript    i='${i}'
        Execute Javascript    document.getElementsByTagName('a')[${i}].click();
        Sleep    0.5s
        Wait Until Element Is Visible    css=a
        ${title_var}    Get Window Titles
        #Select Window    title=${title_var}[${i+1}]
        Log    ${title_var}[${i+1}]
        #SeleniumLibrary.Capture Page Screenshot
        Sleep    0.5s
        Select Window    title=${title_var}[0]
        Exit For Loop If    ${i} == ${elementCount}
    END
    Log    Exited
``

相关问题