【发布时间】:2020-03-21 21:39:58
【问题描述】:
我正在尝试点击网页上的按钮,但一直出现以下错误(抱歉,显然还不能嵌入图像,否则我会在此处放一个屏幕截图)
运行时错误“0”: 硒错误 无效的论点
按钮的Http是
<input type="file" name="import_file" id="import_file" accept=".csv, text/csv">
我试过bot.FindElementById("import_file").Click,但返回了同样的错误,所以我尝试使用名称,同样的错误。
我刚刚尝试过bot.FindElementByCss("input#import_file[type='file'][name='import_file'][accept='.csv, text/csv']").Click 并返回相同的错误...
不确定下一步该尝试什么;有任何想法吗?我的整个子都在下面供参考(密码等,显然被覆盖了)
Sub import_csv()
Dim bot As New WebDriver
bot.Start "chrome", "https://website.com"
bot.Get "/"
'log in
bot.FindElementById("user_login").SendKeys ("####")
bot.FindElementById("user_password").SendKeys ("####")
bot.FindElementByName("commit").Click
'navigate to import screen
bot.Get ("/stocks/import_stocks")
'tick 'File has header row?'
bot.FindElementById("file_has_header").Click
'Click 'Browse...' to open import screen - this is where something isn't working
bot.FindElementByCss("input#import_file[type='file'][name='import_file'][accept='.csv, text/csv']").Click
'import
bot.FindElementByName("commit").Click
bot.SendKeys ("C:\Users\Duane Humphreys\Documents\calendar.CSV")
bot.SendKeys bot.Keys.Enter
bot.FindElementByName("commit").Click
End Sub
编辑: 如果有用的话,我尝试单击的按钮周围的 html 如下所示:
<span class="l-inline-row-block form-file">
<span class="l-inline-col" style="width: 110px;">
<a class="btn-medium btn-alt form-file-btn">
Browse… <input type="file" name="import_file" id="import_file" accept=".csv, text/csv">
</a>
</span>
<span class="l-inline-col">
<input type="text" readonly="">
</span>
</span>
【问题讨论】:
-
尝试将
Get更改为绝对路径 -
好的,可以看到其中的逻辑并将相应地进行修改,但肯定不会对我要解决的问题产生任何影响?
-
这是一个可以设置无条件测试帐户的网站吗?
-
您是否按照建议将 bot.Get "/stocks/import_stocks"(不带括号)更新为绝对路径,但仍然看到相同的错误?
-
@QHarr,不,这是一个仅限员工访问的 ERP 系统,抱歉。不,使用绝对路径并没有解决它。
标签: vba selenium google-chrome css-selectors selenium-chromedriver