首页 > 解决方案 > Powershell脚本将文件导入文件选择文件按钮

问题描述

我正在尝试自动化我需要从网站执行的日常导入。一台服务器正在向网络驱动器生成文件,我想使用特定凭据访问网站日志,然后单击按钮从该网络驱动器输出文件。

我可以登录网站进入正确的页面等。但是当我需要单击“选择文件”并在脚本中选择它时我很挣扎。有没有办法用 PowerShell 做到这一点?

网站示例

路径将始终相同,因此脚本中没有输入。网络路径将类似于 S:\Projects\Link\Uploads\Scheduled_Extracts

该网站的代码是:网站代码

我不确定什么对你有帮助,我正在考虑使用:typedef enum ShellSpecialFolderConstants

但不确定如何。

到目前为止,我的代码如下所示:

$username = Read-Host " Please Enter your email address "

$password = Read-Host -AsSecureString " Please Enter your pasword " 

$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) # translate encrypt password

$ie.Navigate("Website.com")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$usernamefield = $ie.document.getElementByID('username')
$usernamefield.value = "$username"

$passwordfield = $ie.document.getElementByID('password')
$passwordfield.value = "$password"

$Link = $ie.document.getElementByID('_submit')
$Link.click()

Start-Sleep -Seconds 3

$ie.Navigate("Website.com\revelantpPage")
Start-Sleep -Seconds 3

$typefield = $ie.document.getElementByID('import_form_type')
$typefield.value = "2"

# selection of the file

对不起,我真的是PowerShell的初学者

标签: powershellimport

解决方案


推荐阅读