Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium using conditional statements

I just started looking into selenium for automated testing for the past few days and am getting pretty stuck. I've been looking for documentation on this but haven't found anything very helpful but maybe one of you have found something interesting, if so I'd love to read it.

Anyway, here's the problem: I need to open up a website. This website takes in some parameters which takes the browser to another site, however if the parameters are invalid then the next site will display a message saying "An error has occurred".

If the second site doesn't error out like this we want to store a few arbitrary values and echo them later. If the site does error out we want to mark the error and move on. Right now, if the second site is invalid selenium stops running.

The only way it seems to do this is to have an if-else statement though I haven't found any mention of one in selenium. I have read somewhere that you can create some javascript on your own and then input that into selenium. The problem there is that I don't know how to actually input the javascript into selenium.

I hope that wasn't too confusing.

Thank you,

Jesse Smothermon

like image 658
Jesse Smothermon Avatar asked Jun 24 '11 21:06

Jesse Smothermon


People also ask

What are the conditional commands in Selenium?

You can use conditional statements in your code to do this. With if/elseif/else/end you use if to specify a block of code to be executed, if a specified condition is true and use else to specify a block of code to be executed, if the same condition is false.

Is conditional statement supported by Selenium IDE?

Selenium IDE comes with commands that enable you to add conditional logic and looping to your tests. This enables you to execute commands (or a set of commands) only when certain conditions in your application are met, or execute command(s) repeatedly based on pre-defined criteria.

How do you verify or condition in Selenium?

Verify in Selenium (also known as Soft Assertion) In a hard assertion, when the assertion fails, it terminates or aborts the test. If the tester does not want to terminate the script they cannot use hard assertions. To overcome this, one can use soft assertions.


1 Answers

My coworker found it. code below:

<tr>
<td>storeEval</td>
<td>(selenium.isElementPresent("variable_looked_at")?selenium.getText("variable_looked_at"):"N/A")</td>
<td>Address</td>
</tr>

Thanks,

Jesse Smothermon

like image 98
Jesse Smothermon Avatar answered Oct 15 '22 09:10

Jesse Smothermon