我发现循环功能困难,即。从Excel工作表中获取值并执行任务。我有这个网站:http : //dgftebrc.nic.in : 8100/BRCQueryTrade/index.jsp,其中我需要输入IEC代码:
以后输入
装运单号:
我的意思是目前我已经进行了硬编码,但是由于我拥有大量数据并且无法以硬编码方式编写它,因此我无法使其循环运行,因为对于1个IEC编号,我大约有1000 SB。因此可以有100个IEC编号,因此有许多发货单编号(SB.no)。
使用我已解决的标签,但随后使用多个发货单号却导致我遇到问题。
我可以管理这么多的代码:
Option Explicit
Public Sub multipletabtest()
Dim bot As WebDriver
Dim keys As New Selenium.keys
Dim count As Long
Set bot = New WebDriver
bot.Start "Chrome"
'count = 1
'While (Len(Range("A" & count)) > 0)
bot.Get "http://dgftebrc.nic.in:8100/BRCQueryTrade/index.jsp"
bot.FindElementByXPath("//input[@type='text'][@name='iec']").SendKeys "0906008051"
bot.FindElementByXPath("//input[@type='text'][@name='sno']").SendKeys "3929815"
bot.Wait 10000 'Time to enter the captcha
bot.FindElementByCss("[value='Show Details']").SendKeys keys.Control, keys.Enter 'Take the value from final result sheet
bot.SwitchToNextWindow
ThisWorkbook.Sheets("Sheet1").Range("B1") = bot.FindElementByXPath("//text()[.='Used']/ancestor::td[1]").Text
'Range("B" & count) = bot.FindElementByXPath("//text()[.='Used']/ancestor::td[1]").Text 'To extract the data
'bot.Window.Close
bot.SwitchToPreviousWindow
bot.FindElementByXPath("//input[@type='text'][@name='sno']").Clear
bot.FindElementByXPath("//input[@type='text'][@name='sno']").SendKeys "3953913"
bot.FindElementByCss("[value='Show Details']").SendKeys keys.Control, keys.Enter
bot.SwitchToNextWindow
ThisWorkbook.Sheets("Sheet1").Range("B2") = bot.FindElementByXPath("//text()[.='Used']/ancestor::td[1]").Text
'Range("B" & count) = bot.FindElementByXPath("//text()[.='Used']/ancestor::td[1]").Text
'count = count + 1
'Wend
bot.Quit
End Sub
而且因为如果有人想知道为什么按Ctrl + Enter键,那是因为验证码仍然是其他运输法案不相同,所以选择了这个方法。
我也尝试了while语句,但是提取的数据被复制了两次。
Option Explicit
Public Sub multipletabtest()
Dim bot As WebDriver
Dim keys As New Selenium.keys
Dim count As Long
Set bot = New WebDriver
bot.Start "Chrome"
bot.Get "http://dgftebrc.nic.in:8100/BRCQueryTrade/index.jsp"
count = 1
While (Len(Range("A" & count)) > 0)
bot.FindElementByXPath("//input[@name='iec']").SendKeys Range("A" & count)
bot.FindElementByXPath("//input[@name='sno']").SendKeys Range("B" & count)
bot.Wait 10000 'Time to enter the Captcha
bot.FindElementByCss("[value='Show Details']").SendKeys keys.Control, keys.Enter
bot.SwitchToNextWindow
If bot.FindElementsByXPath("//tr[2]//td[7]").count > 0 Then
Range("C" & count) = bot.FindElementByXPath("//tr[2]//td[7]").Text
If bot.FindElementsByXPath("//p[contains(text(),'No Data Found.....check the Input Parameters')]").count > 0 Then
Range("C" & count) = "No Data"
End If
End If
bot.Window.Close
bot.SwitchToPreviousWindow
bot.FindElementByXPath("//input[@type='text'][@name='sno']").Clear
count = count + 1
Wend
bot.Quit
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句