Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get href value in selenium webdriver when javascript is called upon click of a link?

Thank you for reviewing my query. On a webpage, there are more than 200 links & I've ensure all are working. This is easy after fetching href value but the problem is, the 'href' value doesn't contain a link rather a 'javaScript function' Here is a source

<a tabindex="8" title="Internal Crossload" target="_self" href="javascript:fnnHomePage('3' , 'WTMS_EXPRESS')">&nbsp;&nbsp;&nbsp;&nbsp;- Internal Crossload </a>

JavaScript function:

<Script>
    /*********************************************************************
    Function Name          : fnnHomePage
    Input Parameter(s)     : transferTypeId
    Output Parameter(s)    : None
    **********************************************************************/
    function fnnHomePage(transferTypeId ,moduleName) {
        if (moduleName == "XXX_EXPRESS")
     {
            document.getElementById("transferTypeId").value=transferTypeId;
            document.getElementById("gadgetType").value="XXX_EXPRESS";
            document.getElementById("moduleName").value="XXX_EXPRESS";
            document.forms[0].action="/XXX/getProposalHomePage.do?transferTypeId="+transferTypeId;
        document.forms[0].submit();
     }
        if (moduleName ==  "CROSSLOAD")
         {
            document.getElementById("transferTypeId").value=transferTypeId;
            document.getElementById("gadgetType").value="CROSSLOAD";
            document.getElementById("moduleName").value="CROSSLOAD";
            document.forms[0].action="/XXX/getCrossLoadHomePage.do?transferTypeId="+transferTypeId;
            document.forms[0].submit();
         }
    }
</Script>

From the above code, how to I get a 'Link' and check if it is working fine in selenium webdriver? There are several links & each one calls a different 'JavaScript function'.Any suggestions will be appreciated. Thank you.

like image 755
nandesh kalyankar Avatar asked Nov 09 '22 10:11

nandesh kalyankar


1 Answers

You may use a simple trick- click on the link. It will redirect you to the new link generated by javascript function. Then, get the link using driver.getCurrentUrl(); and go back to your original page and do your stuff as usual.

I hope, this makes sense.

like image 69
optimistic_creeper Avatar answered Nov 14 '22 23:11

optimistic_creeper