Is there a way to detect that I'm in a Selenium Webdriver page from JavaScript

前端 未结 5 572
无人共我
无人共我 2021-02-02 17:03

I\'d like to suppress the initialization of TinyMCE inside my tests and can do this easily if the JavaScript can detect that I\'m running inside a Selenium-automated page.

<
5条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 17:58

    Yes, you can do it if someone is using the Firefox driver for Selenium automation, for detection of Selenium driver you have to put in the following code at your client side:

    $(document).ready(function() {
        try{
            if(window.document.documentElement.getAttribute("webdriver"))
                alert("Caught in the first case: Selenium Webdriver is banned!!!");
        }
        catch(Exception)
        {
        }
    
        try{
           if(navigator.webdriver)
               alert("Caught in the second case: Selenium Webdriver is banned!!!");
        }
        catch(Exception)
        {
        }
    });
    

    For Chrome and Internet Explorer specific, the Selenium browser it is not working.

提交回复
热议问题