How to click a button without name Ie and vba

angutir

New Member
Joined
Jan 2, 2012
Messages
4
Hello, i don't know how to press the button with innertext "Selecionar archivo" (in red color) it is a button to open a new window to select a file from computer to upload

This form it is into a iframe:

HTML:
<form name="ficheroForm" method="POST" action="/house/loadfile.do" enctype="multipart/form-data">
		
		//............more code........

<div class="uploader">
<input type="file" name="fichero" size="80%" value="" class="form1" style="opacity: 0; ">
<span class="filename">Seleccionar archivo</span>
[B][COLOR="Red"]<span class="action">Examinar</span>[/COLOR][/B]

</div>


  //.....more code.....

<label><div class="checker"><span>
<input type="checkbox" name="confirmacion" value="true" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; opacity: 0; ">
</span></div> Recibir confirmación vía correo electrónico</label>
									

<div class="button">
<span>Cargar fichero<button *******="aceptar();return false;" style="opacity: 0; ">Cargar fichero</button>
</span></div>


i have a code that go to the web, login with username and password, go to the page for load data (the code above it is embebed into a iframe)

I can click the button with tag "button" with this code:
But the other button don't have property "*******" instead when i pressed with the mouse one window of the OS (not for navigate) open to get the file in my computer

Code:
Set iDoc = ie.Document.frames("curro").Document

Dim boton As Object
        For Each boton In iDoc.getElementsByTagName("button")
             boton.Click      
        Next

And this is the code javascript into the form:


Code:
******** language="JavaScript">
	  
	  function aceptar(){ 
	    var form = document.forms[0];
	    if (form.fichero.value == "") {
	    	mensaje = 'Debe introducir un fichero';
            alert(mensaje);
            form.fichero.focus();
            return false;
	    } else {
		  form.action="cargaFichero.do";    
	      form.submit();
	      cargandoImg();
	    }
	  }
	  
	   function envioFichero(){ 
	    var form = document.forms[0];
	    form.action="cargaFichero.do";    
	    form.submit();
	    cargando();
	  }

	function setFileNameFromPath(path){
		document.forms[0].elements['filename'].value = value = path.substr(path.lastIndexOf('\\') + 1);
		//var oas = new ActiveXObject("Scripting.FileSystemObject");
		//var d = document.a.b.value;
		//var e = oas.getFile(d);
		//var f = e.size;
		//alert(f + " bytes");
	}  

*********>



ie.Navigate ("javascript:envioFichero();") code don't work because the javascript code it is into a iframe and i try with

Set iDoc = ie.Document.frames("curro").Document
ie.iDoc.Navigate ("javascript:envioFichero();") and don' work
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & Welcome to the Board!

May be:
ie.Document.parentWindow.execScript "aceptar();", "JScript"

Regards
 
Upvote 0
Hello Vladimir, thanks for your answer, it works perfectly with little change:

iDoc.parentWindow.execScript "aceptar(path);", "JavaScript"

Because
iDoc = ie.Document.frames("the_name_of_the_iframe").Document


But now i have a problem, i need pass file Path location before execSript "aceptar() because if not the instruction "if (form.file1.value == "") it is true and logically say "you must put a file"

when i do it with the mouse:

1. i click in the button:
HTML:
<span class="action">Explore</span>

2. this button open the tipical window browser files of the windows system

3. I select a valid file and press open

4.With IE 8 browser The totaly file path its show in the box:
HTML:
<span class="filename">Select file</span>
curious note: But with google chrome browser only show the name of file

5. then i click the button :
HTML:
<div class="button">
<span>Load File<button o n c l i c k ="aceptar();return false;" style="opacity: 0; ">load file</button>
</span></div>

5. i have finished


How can i do it with Vba code?

The form it is:
HTML:
<form name="nameForm" method="POST" action="/home/loadFile.do" enctype="multipart/form-data">

The uploader it is:
HTML:
<div class="uploader">
<input type="file" name="file1" size="80%" value="" class="form1" style="opacity: 0; ">
<span class="filename">Select file</span>
<span class="action">Explore</span></div>

The javascript code i can see it is:
Code:
******** language="JavaScript">
	  
	  function aceptar(){ 
	    var form = document.forms[0];
	    if (form.file1.value == "") {
	    	message = 'you must put a file';
            alert(message);
            form.file1.focus();
            return false;
	    } else {
		  form.action="loadfile.do";    
	      form.submit();
	      loadingImg();
	    }
	  }
	  
	   function sendfile(){ 
	    var form = document.forms[0];
	    form.action="loadfile.do";    
	    form.submit();
	    loading();
	  }

	function setFileNameFromPath(path){
		document.forms[0].elements['filename'].value = value = path.substr(path.lastIndexOf('\\') + 1);
		//var oas = new ActiveXObject("Scripting.FileSystemObject");
		//var d = document.a.b.value;
		//var e = oas.getFile(d);
		//var f = e.size;
		//alert(f + " bytes");
	}  

*********>



i try:

iDoc.forms(0).file1.Focus this code works fine and set the focus here :
HTML:
<span class="filename">select file</span>

but it is not allowed to write in, at least in IE 8 (i have the path in the clipboard)

i try:

iDoc.forms(0).file1.value = "C:\Users\................l\AAAAAAAA.999" but don't work (not support this property or method)

also try:

iDoc.parentWindow.execScript "setFileNameFromPath("C:\Users\................l\AAAAAAAA.999");", "JavaScript"

but don't work (runtime error)


maybe if i can open the browser window and paste the path, then sendkey "enter" and call javascript aceptar() but.....

How can i press the button to open the browser file window if there is not envent o n c l i k, there is no name only class= "action"

here is the button:
HTML:
<span class="action">Explore</span>

Thanks Vladimir and happy new year!!!
 
Upvote 0
thanks Vladimir, sorry i have put a post reply to my post, but i wanted replay to your post...i don't know if i have it rigth...
 
Upvote 0
Hello Vladimir, thanks for your answer, it works perfectly with little change:
Glad you've got it working.

But now i have a problem, i need pass file Path location before execSript "aceptar()
It’s hardly to suggest something without debugging (access to web page) possibility.
BTW, setting value for Input Type="File" element is blocked by JavaScrip security.
And style="opacity: 0;" means invisible field - the symptom of the fake element using.

At least in the line below there is a syntax error:
also try:

iDoc.parentWindow.execScript "setFileNameFromPath("C:\Users\................l\AAAAAAAA.999");", "JavaScript"
The doubling of internal quotes (not sure about single quotes) for the path name is required.

Regards
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top