Reputation: 65
So i have this website : http://dgftebrc.nic.in:8100/BRCQueryTrade/index.jsp I need to enter the IEC code and Bank IFSC codes and then a captcha.
IEC codes :
IFSC code :
Later i get a new tab( after i gave sendkeys ctrl+Enter), with a table with Print options(total 200), i need to click on them and save them on my system one by one.
Issues
Someone please look into this and help me out.
So far my code:
Option Explicit
Public Sub downloadpdf()
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='ifsc']").SendKeys Range("B" & count)
bot.Wait 10000 'Time to enter the Captcha
bot.FindElementByCss("[value='Show Details']").SendKeys keys.Control, keys.Enter
bot.SwitchToNextWindow
bot.FindElementByXPath("//tr[2]//td[11]//form[1]//font[1]//input[4]").SendKeys keys.Control, keys.Enter
bot.SwitchToNextWindow
'bot.FindElementByXPath("//*[@id='sidebar']//print-preview-button-strip//cr-button[1]").SendKeys keys.Enter
bot.Window.Close
'bot.Window.Close
bot.SwitchToPreviousWindow
bot.SwitchToPreviousWindow
bot.FindElementByXPath("//input[@name='iec']").Clear
bot.FindElementByXPath("//input[@name='ifsc']").Clear
count = count + 1
Wend
bot.Quit
End Sub
Upvotes: 0
Views: 459
Reputation: 1329
As I could not see any print option in the usl you have shared , below are 2 ways to save pdf from chrome when no download button or option is not given but.
# if any pdf tab opens in chrome during the session that will be auto downloaded
options = webdriver.ChromeOptions()
prefs = {"plugins.always_open_pdf_externally": True}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path="C:\\chrome driver\\chromedriver.exe", options=options)
## 2 if you want to save after sending print to chrome window
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account": ""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2
}
profile = {'printing.print_preview_sticky_settings.appState': json.dumps(appState)}
opt=webdriver.ChromeOptions()
system_user =getpass.getuser()
opt.add_argument("--ignore-certificate-errors")
opt.add_argument("--start-maximized")
# Required for printing
opt.add_experimental_option('prefs', profile)
opt.add_argument('--kiosk-printing')
driver = webdriver.Chrome(executable_path="C:\\chrome driver\\chromedriver.exe", options=opt)
driver.get(www.google.com)
# below line will come post the winow you want to save is visible
driver.execute_script('window.print();')
Upvotes: 1