1

I am trying to program in Excel VBA with selenium to click on a button but the web (http://app.bde.es/rss_www/) has two buttons with the same "Type" and "Class".

<input type="button" class="boton" value="Consultar en PDF" onclick="irAConsulta(document.getElementById('entidad').value, document.getElementById('objetivo').value, document.getElementById('paisRegistro').value, document.getElementById('sector').value, document.getElementById('ejercicio').value, document.getElementById('dimension').value, document.getElementById('pais').value, '0');">

<input type="button" class="boton" value="Consultar en EXCEL" onclick="irAConsultaExcel(document.getElementById('entidad').value, document.getElementById('objetivo').value, document.getElementById('paisRegistro').value, document.getElementById('sector').value, document.getElementById('ejercicio').value, document.getElementById('dimension').value, document.getElementById('pais').value, '0');">

I need to click on the second one to download the data in Excel.

If I type :

OBJ.FindElementByClass("button").Click 

This Clicks on the first one (the PDF), how can I click on the second one for the excel data?

2 Answers 2

2

You can locate that element with XPath or CSS Selector.
By XPath:

OBJ.FindElementByXPath("//input[@value='Consultar en EXCEL']").Click 

By CSS Selector:

OBJ.findElementByCssSelector("input[value='Consultar en EXCEL']").Click 
Sign up to request clarification or add additional context in comments.

Comments

0

FindElementBy* will always return the first matching element. So the locator strategy you have used always returned the first matching element, which is the control for downloading the data in PDF format.

To identify the element for downloading the data in Excel format you need to identify the WebElement uniquely and you can use either of the following Locator Strategies:

  • Using FindElementByCss and onclick attribute:

    OBJ.FindElementByCss("input[onclick^='irAConsultaExcel']").Click
    
  • Using FindElementByCss and value attribute:

    OBJ.FindElementByCss("input[value='Consultar en EXCEL']").Click
    
  • Using FindElementByXPath and onclick attribute:

    OBJ.FindElementByXPath("//input[starts-with(@onclick, 'irAConsultaExcel')]").Click
    
  • Using FindElementByXPath and value attribute:

    OBJ.FindElementByXPath("//input[@value='Consultar en EXCEL']").Click
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.