0

Trying to automate a web-page to fill form. I have an issue where i need to keep entering data according to excel sheet.

So, if i have 2 rows of data in excel i need to click "Add Row" button in the web-page and then fill the form accordingly. And if i have 3 rows in excel, then i need to click twice on "Add Row" button web-page and then fill it.

The approach here (what i have done) is to click the "Add Row" button firstly according to number provided by the user in any cell beforehand. And then fill out the form.

But this does not seem to work.

If ThisWorkbook.Worksheets("Annexure").Range("G8").Value = 2 Then
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click

ElseIf ThisWorkbook.Worksheets("Annexure").Range("G8").Value = 3 Then
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click

ElseIf ThisWorkbook.Worksheets("Annexure").Range("G8").Value = 4 Then
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click

ElseIf ThisWorkbook.Worksheets("Annexure").Range("G8").Value = 5 Then
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click
bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").Click

End If

bot.FindElementById("export-HS-code").SendKeys ThisWorkbook.Worksheets("Annexure").Range("B11")
bot.FindElementById("raw-material-description-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("C11")
bot.FindElementById("raw-material-quantity-unit-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("D11")
bot.FindElementByName("raw_material_unit[1]").SendKeys ThisWorkbook.Worksheets("Annexure").Range("E11")
bot.FindElementById("raw-material-unit-cif-value-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("F11")
bot.FindElementById("raw-material-total-cif-value-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("G11")
bot.FindElementByName("raw_country_id[1]").SendKeys ThisWorkbook.Worksheets("Annexure").Range("H11")
bot.FindElementById("bill-invoice-no-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("I11")
bot.FindElementById("bill-invoice-date-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("J11")
bot.FindElementById("supplier-details-1").SendKeys ThisWorkbook.Worksheets("Annexure").Range("K11")

I know this is not a good way of doing it, because what if i need to click the "Add Row" 10-20 times, this code will not be an efficient way.

Image for Help

Thus asking for help here. Thanks in advance

BigBen
  • 46,229
  • 7
  • 24
  • 40
Amit Shah
  • 65
  • 12
  • for i = 1 to ThisWorkbook.Worksheets("Annexure").Range("G8").Value: bot.FindElementByXPath("//a[@class='add btn-add-raw-materials action']//i[@class='fa fa-plus-circle']").click Assuming 1 is for add 1 more row. Or see if there is a repeat syntax as with sendkeys. You may also need some wait condition to be sure row added. Or use a custom wait clickable js injection via executeScript you can async add (see [this](https://stackoverflow.com/a/54989219/6241235)) – QHarr Jun 16 '20 at 21:38
  • 1
    Also, check if you can simply do this with a POST request to server. – QHarr Jun 16 '20 at 21:44
  • Creating an "import Excel file" function in that app would be much much quicker... and probably less development time, too. Look into Apache POI. (NPOI for C#) – pcalkins Jun 16 '20 at 22:44

0 Answers0