首页 > 解决方案 > 单击“添加行”后如何处理动态行

问题描述

试图自动化一个网页来填写表格。我有一个问题,我需要根据 Excel 表继续输入数据。

因此,如果我在 excel 中有 2 行数据,我需要单击网页中的“添加行”按钮,然后相应地填写表格。如果我在 excel 中有 3 行,那么我需要在“添加行”按钮网页上单击两次,然后填写它。

这里的方法(我所做的)是首先根据用户在任何单元格中提供的数字首先单击“添加行”按钮。然后填写表格。

但这似乎不起作用。

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")

我知道这不是一个好方法,因为如果我需要点击“添加行”10-20 次,这段代码将不是一个有效的方法。

求助图片

因此在这里寻求帮助。 提前致谢

标签: excelvbaseleniumselenium-webdriverselenium-chromedriver

解决方案


推荐阅读