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" 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" 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?
CodePudding user response:
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
CodePudding user response:
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