Python-No such file or directory getAttribute.js

后端 未结 3 397
甜味超标
甜味超标 2021-01-07 14:12

I had a Python selenium program working a week or so ago. Now selenium fails on the import:

from selenium import webdriver

The IDLE ouput:<

3条回答
  •  死守一世寂寞
    2021-01-07 14:57

    The error does gives us some hint on whats wrong happening as follows :

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Mike\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\selenium\\webdriver\\remote\\getAttribute.js'
    

    Which essentially means getAttribute.js wasn't found in it's intended location.

    getAttribute.js

    getAttribute.js file internally works with the errors and other critical JavaScript functions as below :

    • element not selectable
    • element not visible
    • invalid cookie domain
    • invalid element coordinates
    • invalid element state
    • invalid selector
    • invalid selector
    • parseInt()
    • push()
    • indexOf()
    • toUpperCase()
    • execScript()
    • etc

    A typical getAttribute.js file looks like :

    function(){return function(){var d=this;function f(a){return"string"==typeof a};function h(a,b){this.code=a;this.a=l[a]||m;this.message=b||"";a=this.a.replace(/((?:^|\s+)[a-z])/g,function(a){return a.toUpperCase().replace(/^[\s\xa0]+/g,"")});b=a.length-5;if(0>b||a.indexOf("Error",b)!=b)a+="Error";this.name=a;a=Error(this.message);a.name=this.name;this.stack=a.stack||""}
    (function(){var a=Error;function b(){}b.prototype=a.prototype;h.b=a.prototype;h.prototype=new b;h.prototype.constructor=h;h.a=function(b,c,g){for(var e=Array(arguments.length-2),k=2;kparseFloat(D)){C=String(F);break a}}C=D}var G;var H=d.document;G=H&&y?B()||("CSS1Compat"==H.compatMode?parseInt(C,10):5):void 0;var ba=r("Firefox"),ca=v()||r("iPod"),da=r("iPad"),I=r("Android")&&!(w()||r("Firefox")||r("Opera")||r("Silk")),ea=w(),J=r("Safari")&&!(w()||r("Coast")||r("Opera")||r("Edge")||r("Silk")||r("Android"))&&!(v()||r("iPad")||r("iPod"));function K(a){return(a=a.exec(n))?a[1]:""}(function(){if(ba)return K(/Firefox\/([0-9.]+)/);if(y||z||x)return C;if(ea)return v()||r("iPad")||r("iPod")?K(/CriOS\/([0-9.]+)/):K(/Chrome\/([0-9.]+)/);if(J&&!(v()||r("iPad")||r("iPod")))return K(/Version\/([0-9.]+)/);if(ca||da){var a=/Version\/(\S+).*Mobile\/(\S+)/.exec(n);if(a)return a[1]+"."+a[2]}else if(I)return(a=K(/Android\s+([0-9.]+)/))?a:K(/Version\/([0-9.]+)/);return""})();var L,M=function(){if(!A)return!1;var a=d.Components;if(!a)return!1;try{if(!a.classes)return!1}catch(g){return!1}var b=a.classes,a=a.interfaces,e=b["@mozilla.org/xpcom/version-comparator;1"].getService(a.nsIVersionComparator),c=b["@mozilla.org/xre/app-info;1"].getService(a.nsIXULAppInfo).version;L=function(a){e.compare(c,""+a)};return!0}(),N=y&&!(8<=Number(G)),fa=y&&!(9<=Number(G));I&&M&&L(2.3);I&&M&&L(4);J&&M&&L(6);var ga={SCRIPT:1,STYLE:1,HEAD:1,IFRAME:1,OBJECT:1},O={IMG:" ",BR:"\n"};function P(a,b,e){if(!(a.nodeName in ga))if(3==a.nodeType)e?b.push(String(a.nodeValue).replace(/(\r\n|\r|\n)/g,"")):b.push(a.nodeValue);else if(a.nodeName in O)b.push(O[a.nodeName]);else for(a=a.firstChild;a;)P(a,b,e),a=a.nextSibling};function Q(a,b){b=b.toLowerCase();return"style"==b?ha(a.style.cssText):N&&"value"==b&&R(a,"INPUT")?a.value:fa&&!0===a[b]?String(a.getAttribute(b)):(a=a.getAttributeNode(b))&&a.specified?a.value:null}var ia=/[;]+(?=(?:(?:[^"]*"){2})*[^"]*$)(?=(?:(?:[^']*'){2})*[^']*$)(?=(?:[^()]*\([^()]*\))*[^()]*$)/;
    function ha(a){var b=[];t(a.split(ia),function(a){var c=a.indexOf(":");0

    Error Reason :

    Incase the getAttribute.js file doesn't gets downloaded properly Selenium and webdriver modules may not work properly. The issue can arise if the Selenium Client encounters any error during its transmission or storage.

    Selenium Team is currently working on the issue SeleniumHQ/selenium/5378 to generate the binary checksum of the Downloaded Selenium Client which will help you to avoid encountering errors which may have been introduced during its transmission or storage.

    Solution

    Till then a solution will be to :

    • Check if Python is properly installed

      C:\Users\username>python
      Python 3.9.0 (v3.9.0:69c0db5, Jan 31 2018, 17:54:52) [MSC v.1900 32 bit (Intel)]
       on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>>
      
    • Ensure pip is working properly

      C:\Users\username>pip
      
      Usage:
        pip  [options]
      
      Commands:
        install                     Install packages.
        download                    Download packages.
        uninstall                   Uninstall packages.
        freeze                      Output installed packages in requirements format.
        list                        List installed packages.
        show                        Show information about installed packages.
        check                       Verify installed packages have compatible dependencies.
        search                      Search PyPI for packages.
        wheel                       Build wheels from your requirements.
        hash                        Compute hashes of package archives.
        completion                  A helper command used for command completion.
        help                        Show help for commands.
      
      General Options:
        -h, --help                  Show help.
        --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
        -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
        -V, --version               Show version and exit.
        -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
        --log                 Path to a verbose appending log.
        --proxy              Specify a proxy in the form [user:passwd@]proxy.server:port.
        --retries          Maximum number of retries each connection should attempt (default 5 times).
        --timeout              Set the socket timeout (default 15 seconds).
        --exists-action     Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
        --trusted-host    Mark this host as trusted, even though it does not have valid or any HTTPS.
        --cert                Path to alternate CA bundle.
        --client-cert         Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
        --cache-dir            Store the cache data in .
        --no-cache-dir              Disable the cache.
        --disable-pip-version-check
                        Don't periodically check PyPI to determine
                        whether a new version of pip is available for
                    download. Implied with --no-index.
      
    • Uninstall Selenium completely through pip

      C:\Users\username>pip uninstall selenium
      Uninstalling selenium-3.4.2:
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\description.rst
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\installer
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\metadata
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\metadata.json
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\record
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\top_level.txt
        c:\python\lib\site-packages\selenium-3.4.2.dist-info\wheel
        c:\python\lib\site-packages\selenium\__init__.py
        c:\python\lib\site-packages\selenium\__pycache__\__init__.cpython-36.pyc
        c:\python\lib\site-packages\selenium\common\__init__.py
        .....
        .....
        .....  
        c:\python\lib\site-packages\selenium\webdriver\support\events.py
        c:\python\lib\site-packages\selenium\webdriver\support\expected_conditions.py
        c:\python\lib\site-packages\selenium\webdriver\support\select.py
        c:\python\lib\site-packages\selenium\webdriver\support\ui.py
        c:\python\lib\site-packages\selenium\webdriver\support\wait.py
        c:\python\selenium\webdriver\firefox\amd64\x_ignore_nofocus.so
        c:\python\selenium\webdriver\firefox\x86\x_ignore_nofocus.so
        c:\python\selenium\webdriver\remote\getattribute.js
        c:\python\selenium\webdriver\remote\isdisplayed.js
      Proceed (y/n)? y
        Successfully uninstalled selenium-3.4.2
      
    • Install the latest Selenium through pip

      C:\Users\username>pip install -U selenium
      Collecting selenium
        Downloading selenium-3.9.0-py2.py3-none-any.whl (931kB)
          100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 942kB 322kB/s
      Installing collected packages: selenium
      Successfully installed selenium-3.9.0
      
    • Confirm that Selenium is installed

      C:\Users\AtechM_03>pip freeze
      selenium==3.9.0
      
    • Open an IDE (e.g Eclipse, PyCharm) and write a simple program as follows :

      from selenium import webdriver
      
      driver = webdriver.Firefox(executable_path="C:\\path\\to\\geckodriver.exe")
      driver.get('https://stackoverflow.com')
      

提交回复
热议问题