Selenium Send Enter Key returning error "Object required"

71 Views Asked by At

Automating filling in online form in Edge using Selenium within VBA but I am receiving an error message when trying to use the SendKeys for Enter. Note, there is not submit button, Enter is required.

Sub Login()
    'Open online trading platform
    Dim obj As New WebDriver
    obj.Start "edge", ""
    obj.Get "https://standard.tradezeroweb.us/"
    obj.Wait 1000
    obj.Window.Maximize
    obj.FindElementById("trading-order-input-symbol").Clear
    obj.FindElementById("trading-order-input-symbol").SendKeys ("AAPL")
    obj.FindElementById("trading-order-input-symbol").SendKeys (Keys.Enter) 'This is where the code fails
End Sub

Sendkeys (Keys.Enter) returns:

Run-time error '424': Object required

Using obj.FindElementById("trading-order-input-symbol").SendKeys ("AAPL").submit returns:

Run-time error '7': NoSuchElementError

Using obj.FindElementByXPath("//*[@id=trading-order-input-symbol]").SendKeys (obj.Key.Enter) returns:

Run-time error '438': Object doesn't support this property or method

Looking for some assistance and what could be going wrong.

1

There are 1 best solutions below

2
JohnM On

Assuming the "trading-order-input-symbol" element exists then the problem with obj.FindElementById("trading-order-input-symbol").SendKeys (Keys.Enter) (that results in the error 424) is that Keys does not exist by default ... it must be declared.

So, before that line, add a line Dim Keys As New Selenium.Keys.

For info, based on the error you are having, I would guess you do not have Option Explicit at the top of your Module. This is 'hiding' the problem ... you should always use Option Explicit. If you add this (without adding the Dim Keys As New Selenium.Keys line) and compile your project, the VBE will tell you that 'Keys' is not defined - giving you a clue as to what the problem was.