【问题标题】:How can I tell if a variable is emty or not in selenium IDEselenium IDE中如何判断变量是否为空
【发布时间】:2015-05-08 21:27:27
【问题描述】:

我想将使用的协议 (http/https) 存储在一个变量中,但是 Internet Explorer 不响应 window.location.protocol 因此在这种情况下,该变量将为空。在这种情况下,我可以将 https 作为默认设置。 但是我该怎么做呢?

这就是我目前为止所做的。

<tr>
    <td>storeEval</td>
    <td>window.location.protocol</td>
    <td>HOST_PROTOCOL</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>if (${HOST_PROTOCOL}.equals("") { return "https" }</td>
    <td>HOST_PROTOCOL</td>
</tr>

到目前为止,我发现了如何正确使用:

<tr>
    <td>storeEval</td>
    <td>javascript{ if (storedVars['HOST_PROTOCOL'] !="http:" || storedVars['HOST_PROTOCOL'] !="https:") { alert() }  }</td>
    <td>HOST_PROTOCOL</td>
</tr>

现在,如何“返回 https”作为 storeEval 的结果?

【问题讨论】:

    标签: selenium selenium-ide


    【解决方案1】:

    我发现以下内容适用于我的问题

    <tr>
        <td>storeEval</td>
        <td>javascript{ if (window.location.protocol !="http:" || window.location.protocol !="https:") { storedVars['HOST_PROTOCOL']="https:";} else { storedVars['HOST_PROTOCOL']=window.location.protocol } ;true}</td>
        <td>x</td>
    </tr>
    

    我首先检查 window.location.protocol 是 http 还是 https。 如果是这样,我用 window.location.protocol 的值填充我的变量 HOST_PROTOCOL。 在所有其他情况下,我用值“https:”填充我的变量 然后我对 javascript 返回 true,将 selenium 命令传递为绿色。

    【讨论】:

    • 我会说稍微不同:javascript{ if ( window.location.protocol =="https:") { storedVars['HOST_PROTOCOL']="https:"; } else { storedVars['HOST_PROTOCOL']="http:" } ;true}
    • 嗨 DMart,这是一个不错的简短版本,谢谢。您的解决方案唯一的问题是现在无法处理其他协议。
    猜你喜欢
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2012-03-15
    相关资源
    最近更新 更多