Tuesday, April 30, 2013

Let Selenium IDE apply for jobs on behalf of you from your Naukri Account.

     You must be thinking if this is really possible, right? 
Yes, it is possible. You can write Selenium IDE commands such a way that they will go through all your searched jobs or recommended job to apply each one.

After searching and refining the jobs that suits you and your requirements best, you can let IDE take the pain (only in terms of time and patience) of applying those jobs. You can use this time and use it for reading other job posts, job mails or even talk to your gal/boy friend.

[ If you want to automate searching for jobs with Selenium IDE then see our previous posts "Naukri Job search automated" ]

My below code can apply 50 jobs at a stretch (This is also the limit per account per day, I guess)

Automating the job application in Naukri needs below algorithm/steps to be considered.

1. Initialize variables to trace through 50 jobs.
2. Check if a given job was already applied by you.
3. Else, Click on each(UN-applied) job
4. Click "APPLY" button from Job description page.
5. Wait for success/warning message, ignore it and go back to Job description page.
6. Go back to main searched job results page.



Below is a snap shot of the command window:





Remember that the below test case uses flow control commands such as while, gotoIf, label. To make these commands run you should have a latest IDE with you or for older IDE's you can add a flow control JavaScript file from this tutorial http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#goto-sel-ide-js-extension.

 


Commands at a glance:




store |1 | i
storeElementPresent | javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'} | present
while | storedVars['i']<=50 |
gotoIf | storedVars['present']==true | jump1
storeAttribute | javascript{'id='+storedVars['i']+'@href'} | url
echo | ${url} |
open | ${url} |
clickAndWait | id=apply1top |
goBackAndWait |  |
goBackAndWait |  |
label | jump1 |
storeEval | parseInt(storedVars['i'])+1 | i
echo | ${i} |
storeElementPresent | javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'} | present
echo | ${present} |
endWhile |  | 



Commands explained:

 

store |1 | i
We are starting with first job to apply

storeElementPresent | javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'} | present
Check if the image (a tick mark reading "Applied on <date>") present to avoid re-applying for the same job. XPath of the image is //html/body/form/div[i]/div/span/img. We have to replace i with 1 to 50 to check if image is present at each job.

while | storedVars['i']<=50 |
<!--Loop through only 50 jobs-->

gotoIf | storedVars['present']==true | jump1
If the image (a tick mark reading "Applied on <date>") present then do nothing, jump to "Label=jump1" and continue from there incrementing i value and locate the tick image at next job

storeAttribute | javascript{'id='+storedVars['i']+'@href'} | url
Copy URL of the <a> tag (Job name) and store in a variable 'url'

echo | ${url} |
Print the url to console //optional step

open | ${url} |
We are opening the job description page in the same window which otherwise opened in new tab making our commands orphans.

clickAndWait | id=apply1top |
Apply that job you opened.

goBackAndWait |  |
Go back to Job description page.

goBackAndWait |  |
Go back to Searched Job results (main) page.

label | jump1 |
This is where you define a label so that the command "gotoIf" sends the control to this in case the condition fails there.

storeEval | parseInt(storedVars['i'])+1 | i
Increment 'i' value and assign it to itself.

storeElementPresent | javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'} | present
See if that tick image present at the next job item.

endWhile |  |
Restart from while loop for incremented 'i' value.




Below is the HTML source of the above test case to simply copy in your code.

=========================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://login.naukri.com/" />
<title>ApplyJobs</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">ApplyJobs</td></tr>
</thead><tbody>
<tr>
    <td>store</td>
    <td>1</td>
    <td>i</td>
</tr>
<tr>
    <td>storeElementPresent</td>
    <td>javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'}</td>
    <td>present</td>
</tr>
<tr>
    <td>while</td>
    <td>storedVars['i']&lt;=50</td>
    <td></td>
</tr>
<tr>
    <td>gotoIf</td>
    <td>storedVars['present']==true</td>
    <td>jump1</td>
</tr>
<tr>
    <td>storeAttribute</td>
    <td>javascript{'id='+storedVars['i']+'@href'}</td>
    <td>url</td>
</tr>
<tr>
    <td>echo</td>
    <td>${url}</td>
    <td></td>
</tr>
<tr>
    <td>open</td>
    <td>${url}</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=apply1top</td>
    <td></td>
</tr>
<tr>
    <td>goBackAndWait</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>goBackAndWait</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>label</td>
    <td>jump1</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>parseInt(storedVars['i'])+1</td>
    <td>i</td>
</tr>
<tr>
    <td>echo</td>
    <td>${i}</td>
    <td></td>
</tr>
<tr>
    <td>storeElementPresent</td>
    <td>javascript{'//html/body/form/div['+storedVars['i']+']/div/span/img'}</td>
    <td>present</td>
</tr>
<tr>
    <td>echo</td>
    <td>${present}</td>
    <td></td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>
=========================

No comments:

Post a Comment