【发布时间】:2018-11-04 20:19:28
【问题描述】:
所以我有这个程序可以打开我想要保存的 PDF。我以为我已经使用 SetPreferences 绕过了这个 SaveAs 对话框,但这里又是这个对话框。有人成功让 SetPreferences 关闭 SaveAs 对话框吗?
我是否试图将这些首选项设置在程序中的错误位置?我的理解是它发生在机器人启动之前。
Sub CompanyName()
Dim bot As New Selenium.WebDriver
MyFolder = ThisWorkbook.Path
bot.SetPreference "download.default_directory", MyFolder
bot.SetPreference "download.directory_upgrade", True
bot.SetPreference "download.prompt_for_download", False
bot.Start "Chrome", "https://www.intacct.com/ia/acct/login.phtml?[![enter image description here][1]][1]_ga=2.13247287.1007588550.1536894830-1229002215.1536894830"
bot.Get "/"
bot.FindElementById("company").SendKeys "Company ID"
bot.Wait 500
bot.FindElementById("login").SendKeys "Username"
bot.Wait 500
bot.FindElementById("passwd").SendKeys "Password"
bot.Wait 500
bot.FindElementById("retbutton").Click
Stop
'bot.SwitchToParentFrame
Dim menuitem As WebElement
Set menuitem = bot.FindElementByCss("#mainmenu > div > div:nth-child(7) > div.iamenutitlewrapper > span")
bot.Actions.MoveToElement(menuitem).Perform
bot.FindElementByXPath("//span[@class='iamenutitle'][contains(text(),'Accounts Payable')]").Click
bot.FindElementByCss("#mainmenu > div > div:nth-child(7) > div.iamenu.mega.setup-closed > div > div > table > tbody > tr:nth-child(5) > td:nth-child(2) > span:nth-child(2)").Click
bot.SwitchToFrame "iamain"
bot.FindElementByName("F_RECORDID").SendKeys "123"
bot.SendKeys bot.Keys.Enter
bot.Wait 500
bot.FindElementByLinkText("View").Click
bot.Wait 500
bot.FindElementByCss("span.buttons.view_attachment").Click
bot.SwitchToNextWindow
bot.SendKeys bot.Keys.Control, "s"
【问题讨论】:
-
您还可以使用 API 调用来完成另存为过程。 stackoverflow.com/a/52906215/6241235
-
这是文件资源管理器“另存为”对话框还是 Chrome 下载?可以分享一下它的图片吗?
-
完成。抱歉,最初应该是附加的。
-
你可能想试试我上面提到的 API 方法。
标签: excel vba selenium selenium-chromedriver