0
I need your help!
I am developing a VBA application to extract files from an internal system of the company, where after logged in to the site, the displayed screen has a menubar for access to mouseouver, where when passing the mouse on the menu "Reports" opens a list and in the last item of the list that is "Managerial", where I need to do a click event on it to proceed to the next screen, where I will have txtbox date and turn and the buttons to extract the reports. But as I have not yet been able to develop the macro to select the "managerial" menubar item, I am unable to continue.
In short, I need VBA to be able to call the reports menu of javascript where the item is managerial and click to proceed to the next screen.
Below is part of the Java code of the site where I am trying to access:
<h1 id="nomeSist">
IRCS - Sistema de Controle de Reparo e Inspeção
</h1>
<div id="menu_prime" class="ui-outputpanel ui-widget">
<table border="0" class="menuStyle">
<tbody>
<tr>
<td>
<form id="j_id196380812_76b57a10" name="j_id196380812_76b57a10" method="post" action="/tdb-rcs-report/framework/view/dashboard/dashboard.faces" enctype="application/x-www-form-urlencoded">
<div id="j_id196380812_76b57a10:j_id196380812_76b57a6a" class="ui-menu ui-menubar ui-widget ui-widget-content ui-corner-all ui-helper-clearfix" role="menubar">
<div tabindex="0" class="ui-helper-hidden-accessible"></div>
<ul class="ui-menu-list ui-helper-reset">
<li<li class="ui-widget ui-menuitem ui-corner-all ui-menu-parent" role="menuitem" aria-haspopup="true">
**<a href="javascript:void(0)" class="ui-menuitem-link ui-corner-all" tabindex="-1"><span class="ui-menuitem-text">Relatórios</span><span class="ui-icon ui-icon-triangle-1-s"></span></a>**
<ul class="ui-widget-content ui-menu-list ui-corner-all ui-helper-clearfix ui-menu-child ui-shadow" role="menu">
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a tabindex="-1" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57aa6',formId:'j_id196380812_76b57a10'});return false;"><span class="ui-menuitem-text">Diário</span></a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a tabindex="-1" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57aab',formId:'j_id196380812_76b57a10'});return false;"><span class="ui-menuitem-text">Diário Reparo</span></a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a tabindex="-1" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57ab8',formId:'j_id196380812_76b57a10'});return false;"><span class="ui-menuitem-text">Mensal Reparo</span></a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a tabindex="-1" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57a8d',formId:'j_id196380812_76b57a10'});return false;"><span class="ui-menuitem-text">Defeitos por Imagem</span></a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
**<a tabindex="-1" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57a92',formId:'j_id196380812_76b57a10'});return false;"><span class="ui-menuitem-text">Gerencial</span></a>**
</li>
</ul>
</li>
VBA code I am using:
`Dim HTMLdoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "http://tdbsorsvr034/tdb-rcs-report/"
'sURL = "http://tdbsorsvr034/tdb-rcs-report/reports/management/"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = oBrowser.document
HTMLdoc.all.j_username.Value = "BXIMENES"
HTMLdoc.all.j_password.Value = "123456"
HTMLdoc.all.loginBtnId.onclick
'HTMLdoc.all.[ui-menuitem-link ui-corner-all].Value = "PrimeFaces.ab({source:'j_id196380812_76b57a10:j_id196380812_76b57a92',formId:'j_id196380812_76b57a10'})"
For Each oHTML_Element In HTMLdoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
Err_Clear:
Resume Next`
From now on I thank anyone who can help me!
Thank you!
César thanks for the help! So my code does not open any error just does not execute anything after access. The site is intranet, after the login it opens the home screen where has a dropdown menu with 2 items and one of them is the "Reports" that when passing the mouse above opens a list with the items and the last is the "managerial" but I did not find a valid id for it and the link that has for this screen it has a primefaces update scheme that updates the end of the link to each access. Like an access counter I don’t know! I don’t understand very well! So I can’t use the link because it’s not fixed.
– Bruno Ximenes
Actually I found this code on the web and made some changes to use it. But now I found one easier to understand and I started using the other code I changed in the question
– Bruno Ximenes
The relevant part is
For... Each
, the rest is login. The login you said it does right, right? So let’s go to the part of clicking on the menu "managerial".– César Rodriguez
In the HTML you transcribed, the attribute
onclick
that we wish to rotate is in the elementa
, i.e.: we want to click on the elementa
correct. By its explanation, what we have to identify the link is only the internal text of it (or the position within the parent elements, but this path can be very vulnerable to layout changes).– César Rodriguez
So we have to iterate the elements
a
, until you find what has internal text containing "Managerial".– César Rodriguez
That’s what the code I put in the answer should do. Did you test it? I changed the object variable names to match your code.
– César Rodriguez
That Caesar, the part of entering the site works perfectly, I have not yet been able to test the code you went through for being intranet and I can only access in the company. This way due to the holiday we will only return on Wednesday. Hence test executives and inform you ok? Thank you so much for spending part of your time to help me! Strong hug and good holiday!
– Bruno Ximenes
Idem, hug! I do a lot of scripts for my company, and the people here at Stack Overflow helped me a lot, too! I’m happy to help. On hold.
– César Rodriguez
ball show! Hopefully it works! Then I’ll go trying to make the next steps! And I’ll probably need a lot of your help and the forum ;)
– Bruno Ximenes
Good morning Caesar! The code worked in debug mode. It opened right, but when running without debugging it does not open. What could be happening? It did not generate any error code. Does it have to do with the search time of the element? would it need to put a timer to search? I just don’t know how to do it.
– Bruno Ximenes
This has already happened to me. The page has a certain loading speed. In debug mode, you must have given pauses manually that gave time to page load, but in execution mode, pauses do not happen and sometimes the elements we need are not loaded yet!
– César Rodriguez
The
oBrowser.ReadyState
does not mean that the page has just fully loaded, sometimes the browser is ok but an asynchronous part (loaded by ajax, something like that) has not yet come. There the code runs (which is very fast), but the link does not yet exist, so it does not find the correct element and returns aEmpty
. The solution I used was to put another loop after theReadyState
. I’m going to the computer to get an example in my code that should suit you.– César Rodriguez
In the afternoon I managed to find a post here from the forum and I managed to put a timer. So far so good! Now I’m in another problem kkkk I thought that if I was able to access the next page where I have the fields to insert date, turn and print/ generate pdf reports just to call him by Htmldoc.all and the name of the form that was already going and is not happening :( I’ll leave the code below so you can take a look if you can
– Bruno Ximenes
Okay. I’ll tell you one thing: my first option to dribble this was with timer, but at work the Internet was slower, so sometimes I would give the time and not load the element, so I realized that the best was, after the loop
readyState
, put another loop in which it keeps testing if the link already exists.– César Rodriguez
As for the other question, mark this as answered, do the other and put the link here, so it doesn’t get messy.
– César Rodriguez
OK thank you so much for so great help
– Bruno Ximenes
https://answall.com/q/437411/178178 Here is the new post for the new question! Thank you for the provision César!
– Bruno Ximenes
If you can mark this question as answered, help me too
– César Rodriguez
I’ll take a look at the other one.
– César Rodriguez