0

Trying to enter text on google and click a button, getting an exception "Unable to find element" on this line: driverIE.FindElement(By.Id("lst-ib")).SendKeys("Selenium"), although I know the element exists on the pages DOM.

Minimal, Complete, and Verifiable Code

Imports OpenQA.Selenium
Imports OpenQA.Selenium.IE

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim driverIE As New InternetExplorerDriver()
        driverIE.Navigate.GoToUrl("http://google.com")
        driverIE.FindElement(By.Id("lst-ib")).SendKeys("Selenium")
        driverIE.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter)
    End Sub
End Class

Things I've already tried before posting to SO

The IEDriverServer exectuable must be downloaded and placed in your PATH.

On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".

Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog. The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

Footnote: This is not a duplicate of this question: Selenium Unable to Find Element The reason being, I do not want to use explicit Wait(). Thanks!

Community
  • 1
  • 1
JohnWick
  • 4,929
  • 9
  • 37
  • 74
  • Set IE security levels to Medium across the board, and it seems to be working. However, its hitting enter before Selenium has been inserted into the search query textbox. – JohnWick May 10 '17 at 06:13
  • Solved the slow typing issue by using IE x86 instead of x64 as suggested here: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5116 – JohnWick May 10 '17 at 06:20
  • In point of fact, this question is an exact duplicate of the one you linked to. Same root cause, same solution. The `FindElement` method fails because the element you're looking for isn't in the DOM at the moment the driver is looking for it. Remember that the driver is a lot faster than you are, so manually it might seem obvious the element is there, but to the driver is not. You _have_ to wait for the element to be present. `WebDriverWait` is the best solution to that scenario. – JimEvans May 10 '17 at 11:14

0 Answers0