Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium VBA:填充Windows弹出窗口以上载文件_Vba_Windows_Selenium_Path_Popup - Fatal编程技术网

Selenium VBA:填充Windows弹出窗口以上载文件

Selenium VBA:填充Windows弹出窗口以上载文件,vba,windows,selenium,path,popup,Vba,Windows,Selenium,Path,Popup,由于Chrome浏览器的原因,我无法与Windows PopUp交互以编写专用路径,以便使用Selenium在VBA中上载文件 我在Python中找到了一些解决方案,但在VBA中什么都没有。这就是为什么我尝试用VBA转换代码,但没有成功 下面是一个示例代码: Sub Fullfil_Windows_PopUp() Dim driver Dim elem Set Waiter = CreateObject("Selenium.Waiter") Set Assert = Creat

由于Chrome浏览器的原因,我无法与Windows PopUp交互以编写专用路径,以便使用Selenium在VBA中上载文件

我在Python中找到了一些解决方案,但在VBA中什么都没有。这就是为什么我尝试用VBA转换代码,但没有成功

下面是一个示例代码:

Sub Fullfil_Windows_PopUp()
Dim driver
Dim elem

    Set Waiter = CreateObject("Selenium.Waiter")
    Set Assert = CreateObject("Selenium.Assert")
    Set driver = CreateObject("Selenium.ChromeDriver")

    'open the browser and the page
    driver.Get "https://fr.imgbb.com/"
    While Waiter.Not(InStr(driver.Title, "ImgBB — Upload Image — Hébergement d'images gratuit")): Wend

    'open upload window
    Set elem = driver.FindElementsByXPath("//*[@id='home-cover-content']/div[2]/a").Item(1)
    elem.Click

    'Trial 1
    driver.SwitchToWindowByTitle "Ouvrir" '--> NOK (error window not found)
    driver.SendKeys "D:\Test.jpg"

    'Trial 2
    driver.SwitchToAlert.SendKeys "D:\Test.jpg" '--> NOK (error No Alert present)


    'Trial 3
    Set wsh = CreateObject("WScript.Shell")
    wsh.SendKeys "D:\Test.jpg" '--> NOK (no action)


End Sub
提前感谢您的建议

我使用了“后门”将文件名填入filemanager窗口。 由于光标已经进入窗口的filename字段,我在VBS中创建了一个外部脚本来写入文件名(以及2x TAB+ENTER以验证窗口)

下面是VBS文件的代码:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "D:\Test.jpg"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
我在使用selenium打开filemanager窗口后执行此脚本:

Sub Fullfil_Windows_PopUp()
Dim driver
Dim elem

    ' Chrome browser
    Set driver = CreateObject("Selenium.ChromeDriver")

    'open the browser and the page
    driver.Get "https://fr.imgbb.com/"
    Sleep 1000

    ' Open upload window
    Set elem = driver.FindElementsByXPath("//*[@id='home-cover-content']/div[2]/a").Item(1)
    elem.Click

    ' Write the filename with VBS script
    Set oWsh = CreateObject("Shell.Application")
    oWsh.ShellExecute "D:\filename.vbs"
    Set oWsh = Nothing
    Sleep 1500

End Sub

但我继续使用Selenium直接搜索解决方案,因为例如,文件名直接显示在VBS文件中,这不容易像变体一样使用它。

检查您是否有
,谢谢您的回答。如果您对VBA有任何想法,请查看我的答案!谢谢