问题
How can I organize "IF ELSE" in Selenium IDE WITHOUT use extensions?
回答1:
Just to conclude it for future readers:
The "right" and most complete way is to download a
Flow Control
plugin for Selenium IDE from the official page (aaaall the way down).The most useful link I found is this one, because it has a complete example in it: http://selenium.10932.n7.nabble.com/if-else-statement-td4370.html
Anyway, there's also a documentation and author's blogpost explaining something more.
Without any Selenium IDE plugins (what a silly demand - Selenium IDE itself is a plugin!), there's nothing you can do besides writing the whole command in JavaScript. For this, the following functions may come in handy: document.getElementById(), document.getElementsByTagName(), document.getElementsByClassName(), document.querySelectorAll() and document.evaluate().
回答2:
To use If..Else in selenium IDE, first add the plugin "SelBlock"/ link: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-sel-blocks/versions/. After that only you can able to use If..Else in your test case. Example:
<head>
<body>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=signin</td>
<td>test</td>
</tr>
<tr>
<td>echo</td>
<td>${test}</td>
<td></td>
</tr>
<tr>
<td>if</td>
<td>${test}==true</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=signin</td>
<td></td>
</tr>
<tr>
<td>else</td>
<td></td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Logout')])[2]</td>
<td></td>
</tr>
<tr>
<td>endIf</td>
<td></td>
<td></td>
</tr>
</body>
回答3:
Use Gotoif condition.
Here is an example for Gotoif condition:
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=gbqfq</td>
<td>test</td>
</tr>
<tr>
<td>echo</td>
<td>${test}</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>test</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['test']=false</td>
<td>labltest</td>
</tr>
<tr>
<td>type</td>
<td>id=gbqfq</td>
<td>test</td>
</tr>
<tr>
<td>label</td>
<td>labltest</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Thanks,
来源:https://stackoverflow.com/questions/10498966/how-can-i-organize-if-else-in-selenium-ide