Clicking a JavaScript link on website - javascript

I am trying through VBA to generate automatically a report from my bank's website.
I managed to reach the website and plug in my user id and password without any problem. I've reached the page where I can normally generate the report.
Now I have to simulate a click on the link... But I can't manage to do it.
Here is a screenshot of the website, with the HTML code of the link I have to click on to generate the report (Summary Report Copy).
Here is the HTML code of the link I need to click on:
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false" class="">Summary Report Copy</a>
I've tried this line of VBA code, but doesn't work:
IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestatus").FireEvent "onclick"
How can I click on this "Summary Report Copy" thanks to VBA?
Here is the complete HTML code of the part of the webpage where the link is located. Maybe I am not using the right ID?
<td width="290px">
<span id="irCustomStepOne:headerDataTableId:23:reportNmGrp">
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false">Summary Report Copy</a>
<a id="irCustomStepOne:headerDataTableId:23:reportnamePrint" href="#" style="float:left;display:none;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if (!onReportLink(\'23\')) return false;','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamePrint\':\'irCustomStepOne:headerDataTableId:23:reportnamePrint\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Print\'},\'_blank\')');return false">Summary Report Copy</a>
<span id="irCustomStepOne:headerDataTableId:23:rpId" style="float:left;display:none;">3368127</span>
</span>
</td>

This always worked for me. Try it please:
For each lnk in IE.Document.getElementByTagName("a")
If lnk.ID = "irCustomStepOne:headerDataTableId:23:reportnamestat‌​us" Then
lnk.Click
Exit For
Next

You might have to wait for the page to be fully loaded. Something like
Do: VBA.DoEvents: Loop While IE.Busy ' wait for the page to load
Dim el 'As IHTMLElement
Set el = IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestat‌​us")
If el Is Nothing Then el = IE.Document.querySelector("a[title='Summary Report Copy']")
If el Is Nothing Then MsgBox("Link not found!") : Exit Sub
el.click
Do: VBA.DoEvents: Loop While IE.Busy ' wait for next page to load

Related

How can I replace Current page with another page then open current page in another tab

Hello my Wonderful Developers, I need help on this
Let say my website is https://nkiri.pw/ and I want to click on a button or Link, I want my current page to be replace by this page https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3 and my present page should open another page automatically. How can I achieve this successfully ?
I was able to solve it by doing this:
<a role="button" id='mike' href="<?php echo "https://".$_SERVER['SERVER_NAME']."/" ?>" target="_blank" class="btn btn-primary">Primary</a>
<script>let linkElement = document.getElementById("mike"); linkElement.addEventListener("click", openNew);function openNew() {window.open("https://itinerarycarter.com/h9xdx19n?key=2053deb616c8b3ac8566b44a8ec7c092", "_self");}</script>
You are using a hyperlink. So you have a href="" in your html tag. You can also set the target (where the page should be opened) to _blank. This means, that the page will be opened in another tab. So if you write it like this:
href="https://nkiri.pw/" target="_blank"
It will open your current page in another tab. Then you can open the new page with js.
let linkElement = Document.getElementById("yourIdOfTheLinkElement");
linkElement.addEventListener(function() {
window.open("https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3", "_self");
});

Why TWebbrowser IHTMLElement.click fails while mouse click succeeds

I'm trying to auto-fill a web page. Filling input elements and navigating with buttons works fine. Just the final "Save" button fails when programmatically clicking on it, while clicking with the mouse succeeds. The Save button appears to contain some Javascript. In the document it looks like this:
<a title="Enregistrer / Save"
class="btn--icon icon-save ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
id="_save"
onclick="
$('#overlayLoading').dialog('open');
$('#form_model').attr('action', 'https://<some url>');
$('#form_model').submit();"
abp="1909">
<span
class="ui-button-text"
abp="1910">Enregistrer<br
abp="1911">
<span
lang="en"
abp="1912">Save
</span>
</span>
</a>
I tried 3 different approaches:
First approach:
Search for IHTMLelement with id "_save" and do .click()
Navigate() to the URL that is embedded in the element
Executing the JavaScript like this
var
Script: string;
DocPtr: IHTMLDocument2;
WinPtr: IHTMLWindow2;
Script :=
'$(''#overlayLoading'').dialog(''open'');'+
'$(''#form_model'').attr(''action'', ''https://<some url>'');'
'$(''#form_model'').submit();';
if Supports(WB.Document, IHTMLDocument2, DocPtr) and
Supports(DocPtr.parentWindow, IHTMLWindow2, WinPtr) then
WinPtr.execScript(Script, 'javascript');
All 3 methods do seem to work, but the web server returns an error page. When I instead click on the button presented in the TWebBrowser with the mouse, the web server returns success.
What is the physical click doing differently from the programmic click?

Twitter Direct Message Link - Convert <button> into <a>

If you log into twitter, and Direct Message is enabled, you'll see a "Send Message" button appear. I desire that URL. How do I get the URL for sending a specific user a DM? I dug into the code, and this is what we have. Thoughts?
Thanks in advance for your attention buddy.
This is what the button looks like:
Here is the (trimmed) code if you (R) Click > Inspect
`<button type="button" data-name="XYZABCTwitterName" data-screen-name="xyzabctwittername" data-user-id="4203234760" data-original-title="Send a Direct Message to XYZABCTwitterName">
<span>
<span>Message</span>
</span>
</button>`
There is a setup flow here that walks you through it
https://publish.twitter.com/
It generates the a HTML link and script tag to activate it.
Message #realDonaldTrump<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Why does target not working here

First I make an index page containing frame and I named all frames as nasa google you tube etc .
then on search page
<input id="main_category_lan1" value="test" />
<a href="javascript:void(0)"
onmouseover="
window.open('http://nasasearch.nasa.gov/search?utf8=%E2%9C%93&affiliate=nasa&query='
+document.getElementById('main_category_lan1').value)", target="nasa">s</a>
<a href="javascript:void(0)"
onmouseover="window.open('https://www.youtube.com/results?search_query=lecture'
+document.getElementById('main_category_lan1').value)",target="google">e</a>
but this is not working ,every time it open in new tab. Also I want to open both the pages bye a single button.
What should I do? Thanks.
Pass _self in target.
Read this link for more info about target
http://www.w3schools.com/tags/att_base_target.asp

Scrapy parsing of the hidden information appearing after link click

I try to parse some hidden information:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="some_link/some_hash"
onclick="return showInfo(event)">Info showed here after click</a>
When I manually click to this link, only get request to http://www.google-analytics.com appears at the firebug. And page not reloaded - only info showed as a link text.
How can I get info by scrapy?
I did not understand very well if what you're trying to get is to show some info inside the a tag or in other part of the page. But in any of the cases that will also depend on what does the showInfo() function return.
If the first case is what you need and showInfo() returns the text with the info, i believe this is what you're looking for:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="#" onclick="this.innerHTML=showInfo(event)">
Info showed here after click
</a>
Here's a demo with the example http://jsfiddle.net/P49Dv/ ;)

Categories