如何将文本替换为右侧?

时间:2013-03-22 03:34:49

标签: selenium-ide

[info] echo: AB: 889614 | YX: 43 | ZY: 889571
[info] Executing: |store | javascript{storedVars.BLA.replace('AB: ','')} | BLA2 |
[info] Executing: |store | javascript{storedVars.BLA2.replace(' |-','')} | BLA3 |
[info] Executing: |echo | ${BLA3} | |
[info] echo: 889614 | YX: 43 | ZY: 889571 

如何在Selenium IDE中将HTML替换为右侧文本?

我喜欢只获取变量中的第一个数字。

有人能告诉我一个如何做到这一点的例子吗?

2 个答案:

答案 0 :(得分:1)

您要分割句子并仅存储数值。使用下面的代码

  <tr>
    <td>store</td>
    <td>AB: 889614 | YX: 43 | ZY: 889571</td>
    <td>num1</td>
  </tr>

 <tr>
    <td>store</td>
    <td>1</td>
    <td>dim</td>
 </tr>
 <tr>
    <td>store</td>
    <td>javascript{storedVars['num1'].split('AB:')[storedVars['dim']]}</td>
    <td>num2</td>
 </tr>
 <tr>
    <td>store</td>
    <td>0</td>
    <td>dim1</td>
 </tr>
 <tr>
    <td>store</td>
    <td>javascript{storedVars['num2'].split('| ')[storedVars['dim1']]}</td>
    <td>num3</td>
 </tr>
 <tr>
    <td>echo</td>
    <td>${num3}</td>
    <td></td>
 </tr>
 <tr>
    <td>store</td>
    <td>1</td>
    <td>dim2</td>
 </tr>
 <tr>
    <td>store</td>
    <td>javascript{storedVars['num1'].split('YX:')[storedVars['dim2']]}</td>
    <td>num4</td>
 </tr>
 <tr>
    <td>echo</td>
    <td>${num4}</td>
    <td></td>
 </tr>
 <tr>
    <td>store</td>
    <td>0</td>
    <td>dim3</td>
 </tr>
 <tr>
    <td>store</td>
    <td>javascript{storedVars['num4'].split('| ')[storedVars['dim3']]}</td>
    <td>num5</td>
 </tr>
 <tr>
    <td>echo</td>
    <td>${num5}</td>
    <td></td>
  </tr>
  <tr>
    <td>store</td>
    <td>1</td>
    <td>dim4</td>
  </tr>
  <tr>
    <td>store</td>
    <td>javascript{storedVars['num1'].split('ZY:')[storedVars['dim4']]}</td>
    <td>num6</td>
  </tr>
  <tr>
    <td>echo</td>
    <td>${num6}</td>
    <td></td>
 </tr>

在selenium ide中执行上述命令

       [info] Executing: |store | AB: 889614 | YX: 43 | ZY: 889571 | num1 |
       [info] Executing: |store | 1 | dim |
       [info] Executing: |store | javascript{storedVars['num1'].split('AB:')[storedVars['dim']]} | num2 |
       [info] Executing: |store | 0 | dim1 |
       [info] Executing: |store | javascript{storedVars['num2'].split('| ')[storedVars['dim1']]} | num3 |
       [info] Executing: |echo | ${num3} | |
       [info] echo: 889614
       [info] Executing: |store | 1 | dim2 |
       [info] Executing: |store | javascript{storedVars['num1'].split('YX:')[storedVars['dim2']]} | num4 |
       [info] Executing: |echo | ${num4} | |
       [info] echo: 43 | ZY: 889571
       [info] Executing: |store | 0 | dim3 |
       [info] Executing: |store | javascript{storedVars['num4'].split('| ')[storedVars['dim3']]} | num5 |
       [info] Executing: |echo | ${num5} | |
       [info] echo: 43
       [info] Executing: |store | 1 | dim4 |
       [info] Executing: |store | javascript{storedVars['num1'].split('ZY:')[storedVars['dim4']]} | num6 |
       [info] Executing: |echo | ${num6} | |
       [info] echo: 889571 

答案 1 :(得分:0)

因此,如果您正在寻找<{p}}中的889614

AB: 889614 | YX: 43 | ZY: 889571

然后你可以尝试下面的解决方案 -

store | AB: 889614 | YX: 43 | ZY: 889571  | var1
store | 1 | delimiter
store | javascript{storedVars['var1'].split('AB:')[storedVars['delimiter']]} | var2
store | 0 | delimiter1
store | javascript{storedVars['var2'].split('| ')[storedVars['delimiter1']]}  |variable
echo  | ${variable}