1

我将此代码测试到一个静态 HTML 页面,它工作正常。我尝试将以下内容添加到 Selenium 并得到“[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2531”。我认为它没有存储值:

runScript | {codebelow}
echo | javascript{storedVars['dropdowns']}

在 Selenium 中,我去掉了“函数”之前的空格(这是上面的 {codebelow}):

  function loop_dropdown(label){

        regions = window.document.getElementsByName(label)[0].children;
        idx=0;
        for (var i=0; i<regions.length;i++) {
            option = regions[i];
            if (option.value != -1)  //Don't Use the All Option
            {   var entry = {};
                entry.value_num = option.value;
                entry.value_txt = option.innerHTML;
                dropdowns[idx]=entry;
                idx++;
            }
        }
    storedVars['dropdowns'] = dropdowns;
    //document.write(storedVars['dropdowns'][0].value_num);
    //document.write(storedVars['dropdowns'][0].value_txt);
}
loop_dropdown('region');

在静态 HTML 页面中:

<head>

            <script type="text/javascript">
                //if (test)
                                var storedVars = [];
                    var dropdowns = [];
            </script>

            <script type="text/javascript">
                function loop_dropdown(label){

                    regions = window.document.getElementsByName(label)[0].children;
                    idx=0;
                    for (var i=0; i<regions.length;i++) {
                        option = regions[i];
                        if (option.value != -1)  //Don't Use the All Option
                        {   var entry = {};
                            entry.value_num = option.value;
                            entry.value_txt = option.innerHTML;
                            dropdowns[idx]=entry;
                            idx++;
                        }
                    }
                storedVars['dropdowns'] = dropdowns;
                //document.write(storedVars['dropdowns'][0].value_num);
                //document.write(storedVars['dropdowns'][0].value_txt);
            }
            </script>
...<body>...
        <script type="text/javascript">loop_dropdown('region');</script>
4

0 回答 0