Selenium IDE - 将 URL 字符串变量传递到条件“gotoIf”语句中会引发语法错误?

问题描述 投票:0回答:3

我正在尝试将当前 url (http://example.com) 存储在一个变量中,并将其与另一个字符串进行比较,作为 gotoIf 命令中的条件(gotoIf extension.js 的一部分):

    storeLocation || url
    gotoIf || ${url}=="http://example.com" || label

当我运行这个 seleniun ide 时会抛出此错误:

[error] Unexpected Exception: message -> syntax error, fileName -> chrome://selenium-ide/content/tools.js -> file:///C:/Users/David%20Cunningham/Desktop/extensions_js/extensions.js, lineNumber -> 183, stack -> eval("http://example.com==\"http://example.com\"")@:0 ("http://example.com==\"http://example.com\"","label1")@chrome://selenium-ide/content/tools.js -> file:///C:/Users/David%20Cunningham/Desktop/extensions_js/extensions.js:183 ("http://example.com==\"http://example.com\"","label1")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:310 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (6)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 (6)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 , name -> SyntaxError 

storeLocation 应该返回一个字符串,那么为什么我会收到此错误,语法有什么问题以及如何声明此命令?

javascript selenium-webdriver selenium-ide
3个回答
1
投票

错误信息显示:

eval("http://example.com==\"http://example.com\"")

你或许应该改变你的表情:

转到如果|| “${url}”==“http://example.com”||标签

这样你就会得到一个有效的表达式:

eval("\"http://example.com\"==\"http://example.com\"")

1
投票

是的..这很好用

gotoIf || "${x}"=="${y}"

0
投票
try out this one   

 <tr>
        <td>storeLocation</td>
        <td>j</td>
        <td></td>
    </tr>
    <tr>
        <td>echo</td>
        <td>${j}</td>
        <td></td>
    </tr>
    <tr>
        <td>store</td>
        <td>http://www.google.com</td>
        <td>i</td>
    </tr>
    <tr>
        <td>echo</td>
        <td>${i}</td>
        <td></td>
    </tr>
    <tr>
        <td>gotoIf</td>
        <td>storedVars['i']==storedVars['j']</td>
        <td>label</td>
    </tr>
© www.soinside.com 2019 - 2024. All rights reserved.