Excel 在选项卡和框架之间切换
所以我有一个网站: 我需要输入IEC代码和银行IFSC代码,然后输入验证码 IEC代码:Excel 在选项卡和框架之间切换,excel,vba,selenium,selenium-webdriver,Excel,Vba,Selenium,Selenium Webdriver,所以我有一个网站: 我需要输入IEC代码和银行IFSC代码,然后输入验证码 IEC代码: 039203249 0906008051 IFSC代码: HDFC0000102 DEUT0797TRS 后来,我得到了一个新的选项卡(在我给sendkeys ctrl+Enter之后),其中有一个带有Print选项(总共200个)的表,我需要单击它们并将它们逐个保存在我的系统中 问题 我想我可以用CTrl+Enter键点击打印选项,这样它就会在一个新的选项卡中打开,然后我可以点击Enter键,将文件保存为
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
由于我在您共享的usl中看不到任何打印选项,下面是两种在没有提供下载按钮或选项的情况下从chrome保存pdf的方法
# 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();')
在我的场景中有一个“打印”按钮。这需要点击,弹出一个单独的标签,然后自动Chrome Pdf阅读器打开并要求另存为“.Pdf”。它在那里,我无法访问,因为它超出了框架。我如何才能达到打印按钮,因为在链接中,你没有共享打印按钮那里。。如果pdf在新选项卡中打开,则第一种方法应该有效。。我将尝试搜索一些示例linkHi先生,只要你点击提交按钮,就会有一个包含如此多行的页面,然后每行都有一个“打印”选项。我现在也添加了图像。很抱歉耽搁了,我保存不好。@AmitShah给我一些样本数据供我使用。先生,样本数据已经存在于问题中,现在我已经编辑了它,认为它是不可读的格式。现在你可以看看了。