Search code examples
javascriptdomhrefimacros

Using iMacros to click on JavaScript link using the title in an "a" with document.querySelector()?


I need to click on the "Save Changes" link with my iMacros script but somehow I am unable to. Here is the link and its surrounding HTML Code:

    <span id="ctl09_ctl00_avbSavePropertySettings">
            <table Title="" class="printhide" cellpadding="0" cellspacing="0" border="0" 
            onmouseover="self.status=&#39;Save the changes to the property.&#39;;return true;" 
            onmouseout="self.status=&#39;&#39;;return true;">
            <tr><td class="AvidButton-left" width="12" height="17" rowspan="3"></td>
            <td class="AvidButton-top" height="3"></td>
            <td class="AvidButton-right" width="7" height="17" rowspan="3"></td></tr>
            <tr>
            <td nowrap="nowrap" class="AvidButton-text" height="11">
        <a onclick="return propertyClass.save(this);" title="Save Changes" 
        href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions
       (&quot;ctl09$ctl00$avbSavePropertySettings$ctl07&quot;, 
        &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">Save Changes</a></td>
            </tr>
            <tr><td class="AvidButton-bottom" height="3"></td></tr>
            </table>
            </span>

This has worked when I try the Chrome developer tools:

document.querySelector("a[title='Save Changes']").click();

But it doesn't work when i try to use this inside my iMacros code:

URL GOTO=javascript:document.querySelector("a[title='Save Changes']").click();

Here are some of the other commands I have tried:

TAG SELECTOR="#ctl09_ctl00_avbSavePropertySettings>TABLE>TBODY>TR:nth-of-type(2)>TD>A"

TAG XPATH="./a[contains(.,'Save Changes')]

TAG SELECTOR="#ctl09_ctl00_avbSavePropertySettings>TABLE>TBODY>TR:nth-of-type(2)>TD>A"

TAG POS=1 TYPE=A ATTR=TXT:Save<SP>Changes

TAG XPATH="//*[@id="ctl09_ctl00_avbSavePropertySettings"]/table/tbody/tr[2]/td/a"

TAG XPATH="//*[@id="ctl09_ctl00_avbSavePropertySettings"]/table/tbody/tr[2]/td/a"

EVENT TYPE=CLICK XPATH="//*[@id="ctl09_ctl00_avbSavePropertySettings"]/table/tbody/tr[2]/td/a"

TAG POS=1 TYPE=A ATTR=TITLE:"Save Changes"

Any advice is welcome - I have spent far too long on this already!

Thanks so much!


Solution

  • Perhaps the following line of code will be helpful to you:

    EVENT TYPE=CLICK SELECTOR="a[title='Save Changes']"
    

    You can also try this:

    URL GOTO=javascript:document.querySelector("a[title='Save<SP>Changes']").click();