1

I'm trying to click a button on a webpage, and keep getting the below error (sorry, can't embed images yet apparently, otherwise I would put a screenshot on here)

Run-time error '0': SeleniumError invalid argument

The Http for the button is

<input type="file" name="import_file" id="import_file" accept=".csv, text/csv">

I've tried bot.FindElementById("import_file").Clickand that returned the same error, so I then tried using the name, same error.

I've just tried bot.FindElementByCss("input#import_file[type='file'][name='import_file'][accept='.csv, text/csv']").Click and that returns the same error...

Not sure what to try next; any ideas? My entire sub is below for reference (with passwords, etc, overwritten obviously)

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

EDIT: The html surrounding the button I'm trying to click is below, if that's useful:

<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>
newuser2967
  • 316
  • 1
  • 4
  • 15

2 Answers2

1

I don't think this has solved the root cause of whatever is happening here, but I've managed to get round it with

bot.FindElementById("import_file").ClickAndHold
bot.SendKeys bot.Keys.Enter

I still have no idea why .ClickAndHold works and .click doesn't, but this will work for now. LMK if there's a cleaner way to achieve the same thing.

newuser2967
  • 316
  • 1
  • 4
  • 15
0

Invalid argument

The invalid argument error is a WebDriver error that occurs when the arguments passed to a command are either invalid or malformed.


This error message...

Run-time error '0': SeleniumError invalid argument

...implies that the arguments passed to a command are either invalid or malformed.

From the WebDriver - W3C Living Document:

invalid_argument

There seems to be a minor issue with the presence of the dot character i.e. . with in the Locator Strategy you have used. In short, you need to avoid the . character in your locators. You can use either of the following solutions:

bot.FindElementByCss("input#import_file[type='file'][name='import_file'][accept*='csv']").Click

Or

bot.FindElementByCss("input#import_file[type='file'][name='import_file'][accept$='text/csv']").Click
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352