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>
5
  • Try to change Get to absolute path wherever it occur Commented Nov 26, 2019 at 14:26
  • OK, can see the logic in that and will amend accordingly, but surely won't make any difference to the issue I'm trying to solve? Commented Nov 26, 2019 at 14:33
  • is this a site where one can set up a no strings test account? Commented Nov 26, 2019 at 19:14
  • And did you update bot.Get "/stocks/import_stocks" (without the parentheses) to absolute path as suggested and still see same error? Commented Nov 26, 2019 at 19:16
  • 1
    @QHarr, no, this is an ERP system with access restricted to employees, sorry. And no, using absolute path hasn't fixed it. Commented Nov 27, 2019 at 10:19

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

5 Comments

Thanks for the input @DebanjanB, and I can see the logic, but neither of them have worked. The element name is actually unique without the 'accepts' property, so I've tried it without that, and it still doesn't work. I've added the html around the button in the original question, if that's of any use
@dhumphreys Apply some wait for the element to be clickable before trying to identify the element and invoking click()
OK, so after bot.FindElementById("file_has_header").Click ?
@dhumphreys Yes, after bot.FindElementById("file_has_header").Click
@dhumphreys Are you seeing the same error? Else update the question with the current error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.