Wednesday, October 30, 2013

How to book IRCTC tatkal tickets using Selenium IDE ? - Part 1.5

        Please refer to first part at How to book IRCTC tatkal tickets using Selenium IDE? before reading this article to understand the context.

This part is specially added in response to an user request. This part discusses about choosing a train and class before we fill the passenger information. This is usually done after we find the trains by providing From and To information. The below code finds the train number we gave as input in the list of trains shown and select a class (i.e, clicks on the checkbox) corresponding to the train number.

We should be having a train number and travel class with us and then we can make our selenese commands select them.


 Here is how it is drafted.



 Source

 ------------------------------------------------
<tr>
<td>store</td>
<td>//td/table/tbody/tr//td/div/table/tbody/tr[</td>
<td>part1</td>
</tr>
<tr>
<td>store</td>
<td>]/td[@class='border-btm']</td>
<td>part2</td>
</tr>
<tr>
<td>store</td>
<td>]/td[11]/input[@value='SL']</td>
<td>part3</td>
</tr>
<tr>
<td>store</td>
<td>123</td>
<td>value</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>${value}!=12728</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['part1']+storedVars['i']+storedVars['part2']</td>
<td>path</td>
</tr>
<tr>
<td>storeText</td>
<td>javascript{storedVars['path']}</td>
<td>value</td>
</tr>
<tr>
<td>echo</td>
<td>${value}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>parseInt(storedVars['i'])+1</td>
<td>i</td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>javascript{storedVars['part1']+(storedVars['i']-1)+storedVars['part3']}</td>
<td></td>
</tr>
 ------------------------------------------------

 Explanation:

-> Take the xpath of the train number and split into part1 and part2.

-> Take the xpath of the class and split into two parts. here first part equals to part1 of train number xpath and second one is named as part3.

-> In while loop, combine part1 and part2 to check ll train numbers in order and quit the loop if it finds the train number we are searching for.

-> Select the class after we quit the while which means we found the train number and we go to corresponding class with help of the value of "i".

-> Remember that the class is sleeper here (You can change it to any thing else)

  

1 comment:

  1. Thanks for posting the full details,its really a good information
    pnr status

    ReplyDelete