0

Is there a tell-tale or marker or variable created by InternetExplorerDriver in the javascript environment of the browser being remotely controlled that can be used to create javascript code in a web page that detects whether the browser is (obviously MSIE) and is being controlled by Selenium WebDriver through InternetExplorerDriver?

sevzas
  • 701
  • 2
  • 5
  • 13

2 Answers2

1

According to the W3C WebDriver Specification, the driver is supposed to set a property on the navigator object, specifically navigator.webdriver, that would allow detection. Unfortunately, this is one of the few places that the IE driver does not adhere to the spec at present.

Knowing the internal structure of the driver, you could look for document.__webdriver_script_fn, which is a variable used by the driver to execute JavaScript. Note carefully, that this JavaScript execution variable is used by several internal functions of the driver, not just explicit calls to the Selenium executeScript method. Be aware, though, that this is an implementation detail, and is likely to change without notice. In point of fact, the development team is researching rearchitecture options for the 4.x development cycle that would so away with it altogether.

If you were a little more explicit as to why you want to detect such a thing, it might be possible to offer more concrete and forward-looking guidance. However, at the time of this writing, this is likely the best you’ll be able to do.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • I'm trying to detect WebDriver to prevent scrapers on my web site. Upon loading a page in IE through IEDriverServer.exe I bring up developer tools F12 and I don't see document.__webdriver_script_fn - does it appear right away or is some interaction with the browser necessary? Thanks for responding - I noticed that you have all of the commits on this Selenium component, so you're the most qualified to answer. – sevzas Dec 21 '18 at 22:39
  • No, as I said, the property is created when the driver executes JavaScript. Again, the driver does that for a fair number of actions with the browser. But until it does so, you won’t detect it. – JimEvans Dec 22 '18 at 02:06
  • Then I gather that the answer is "at present there is no reliable way to detect IEDriverServer". – sevzas Dec 22 '18 at 13:35
0

Internet Explorer can be detected in Front End by checking specific properties on window.navigator object.

As you mentioned that you want to add some code to the webpage, you may also - assuming that Front End code is using some kind of bundler - use one of "browser detect" packages from NPM.

I personally prefer and suggest to use this one - Bowser: https://www.npmjs.com/package/bowser

If you want to detect whether your IE instance is controlled by Selenium, then you may check for specific variables that Selenium exposes on the browser.

I'm not sure about IE in that case, but there's definitely a similar way of doing so. The answer can be found here: Can a website detect when you are using selenium with chromedriver?

Note that using InternetExplorerDriver is equal to using Selenium, as that's the only IE driver, so detecting Selenium context should be enough, I suppose.

SzybkiSasza
  • 1,591
  • 12
  • 27
  • I'm trying to detect whether it's Internet Explorer which is driven by InternetExplorerDriver which is a component of the Remote Control framework Selenium Webdriver. I think you're answering the question "how can I detect Internet Explorer". Interestingly, there is a property window.navigator.webdriver but it's set to false on a remotely-controlled IE window. – sevzas Dec 21 '18 at 15:44
  • Do you mean differentiating between pure IE (not running in Selenium context) and one used by Selenium via InternetExplorerDriver? – SzybkiSasza Dec 21 '18 at 15:58