Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capability error can't run pylenium #301

Closed
beu-adesso opened this issue Jun 12, 2023 · 4 comments
Closed

capability error can't run pylenium #301

beu-adesso opened this issue Jun 12, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@beu-adesso
Copy link

beu-adesso commented Jun 12, 2023

Hi,
I'm following the getting started, and getting on windows and on linux(ubuntu) the exception:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: unrecognized capability: name

Full Stack Trace on Linux
   tests/test_example.py:3 (test_google)
py = <pylenium.driver.Pylenium object at 0x7fb7cf738110>

    def test_google(py: Pylenium):
>       py.visit('https://lambdatest.github.io/sample-todo-app/')

tests/test_example.py:5: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:359: in visit
    self.webdriver.get(url)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:232: in webdriver
    return self.init_webdriver() if self._webdriver is None else self._webdriver
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:200: in init_webdriver
    self._webdriver = webdriver_factory.build_from_config(self.config)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/webdriver_factory.py:149: in build_from_config
    return build_firefox(seleniumwire_options=config.driver.seleniumwire_options, **_config)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/webdriver_factory.py:267: in build_firefox
    return wire_driver.Firefox(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError("'Firefox' object has no attribute 'session_id'") raised in repr()] Firefox object at 0x7fb7cfeb92d0>
seleniumwire_options = {}, args = ()
kwargs = {'capabilities': {'acceptInsecureCerts': True, 'browserName': 'firefox', 'moz:debuggerAddress': True, 'name': 'test_go...ns.Options object at 0x7fb7cf73d750>, 'service': <selenium.webdriver.firefox.service.Service object at 0x7fb7d308cc50>}
firefox_options = <selenium.webdriver.firefox.options.Options object at 0x7fb7cf73d750>
config = {'acceptInsecureCerts': True, 'proxy': {'httpProxy': '127.0.0.1:40055', 'proxyType': 'manual', 'sslProxy': '127.0.0.1:40055'}}
proxy = <selenium.webdriver.common.proxy.Proxy object at 0x7fb7cf75c550>

    def __init__(self, *args, seleniumwire_options=None, **kwargs):
        """Initialise a new Firefox WebDriver instance.
    
        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        """
        if seleniumwire_options is None:
            seleniumwire_options = {}
    
        try:
            firefox_options = kwargs['options']
        except KeyError:
            firefox_options = FirefoxOptions()
            kwargs['options'] = firefox_options
    
        # Prevent Firefox from bypassing the Selenium Wire proxy
        # for localhost addresses.
        firefox_options.set_preference('network.proxy.allow_hijacking_localhost', True)
        firefox_options.accept_insecure_certs = True
    
        config = self._setup_backend(seleniumwire_options)
    
        if seleniumwire_options.get('auto_config', True):
            if SELENIUM_V4:
                # From Selenium v4.0.0 the browser's proxy settings can no longer
                # be passed using desired capabilities and we must use the options
                # object instead.
                proxy = Proxy()
                proxy.http_proxy = config['proxy']['httpProxy']
                proxy.ssl_proxy = config['proxy']['sslProxy']
    
                try:
                    proxy.no_proxy = config['proxy']['noProxy']
                except KeyError:
                    pass
    
                firefox_options.proxy = proxy
            else:
                # Earlier versions of Selenium use capabilities to pass the settings.
                capabilities = kwargs.get('capabilities', kwargs.get('desired_capabilities'))
                if capabilities is None:
                    capabilities = DesiredCapabilities.FIREFOX
                capabilities = capabilities.copy()
    
                capabilities.update(config)
                kwargs['capabilities'] = capabilities
    
>       super().__init__(*args, **kwargs)
E       TypeError: WebDriver.__init__() got an unexpected keyword argument 'capabilities'

../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/seleniumwire/webdriver.py:179: TypeError

With Firefox i get on both:
TypeError: WebDriver.__init__() got an unexpected keyword argument 'capabilities'

Full stack trace on Linux
   tests/test_example.py:3 (test_google)
py = <pylenium.driver.Pylenium object at 0x7fb7cf738110>

    def test_google(py: Pylenium):
>       py.visit('https://lambdatest.github.io/sample-todo-app/')

tests/test_example.py:5: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:359: in visit
    self.webdriver.get(url)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:232: in webdriver
    return self.init_webdriver() if self._webdriver is None else self._webdriver
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/driver.py:200: in init_webdriver
    self._webdriver = webdriver_factory.build_from_config(self.config)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/webdriver_factory.py:149: in build_from_config
    return build_firefox(seleniumwire_options=config.driver.seleniumwire_options, **_config)
../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/pylenium/webdriver_factory.py:267: in build_firefox
    return wire_driver.Firefox(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError("'Firefox' object has no attribute 'session_id'") raised in repr()] Firefox object at 0x7fb7cfeb92d0>
seleniumwire_options = {}, args = ()
kwargs = {'capabilities': {'acceptInsecureCerts': True, 'browserName': 'firefox', 'moz:debuggerAddress': True, 'name': 'test_go...ns.Options object at 0x7fb7cf73d750>, 'service': <selenium.webdriver.firefox.service.Service object at 0x7fb7d308cc50>}
firefox_options = <selenium.webdriver.firefox.options.Options object at 0x7fb7cf73d750>
config = {'acceptInsecureCerts': True, 'proxy': {'httpProxy': '127.0.0.1:40055', 'proxyType': 'manual', 'sslProxy': '127.0.0.1:40055'}}
proxy = <selenium.webdriver.common.proxy.Proxy object at 0x7fb7cf75c550>

    def __init__(self, *args, seleniumwire_options=None, **kwargs):
        """Initialise a new Firefox WebDriver instance.
    
        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        """
        if seleniumwire_options is None:
            seleniumwire_options = {}
    
        try:
            firefox_options = kwargs['options']
        except KeyError:
            firefox_options = FirefoxOptions()
            kwargs['options'] = firefox_options
    
        # Prevent Firefox from bypassing the Selenium Wire proxy
        # for localhost addresses.
        firefox_options.set_preference('network.proxy.allow_hijacking_localhost', True)
        firefox_options.accept_insecure_certs = True
    
        config = self._setup_backend(seleniumwire_options)
    
        if seleniumwire_options.get('auto_config', True):
            if SELENIUM_V4:
                # From Selenium v4.0.0 the browser's proxy settings can no longer
                # be passed using desired capabilities and we must use the options
                # object instead.
                proxy = Proxy()
                proxy.http_proxy = config['proxy']['httpProxy']
                proxy.ssl_proxy = config['proxy']['sslProxy']
    
                try:
                    proxy.no_proxy = config['proxy']['noProxy']
                except KeyError:
                    pass
    
                firefox_options.proxy = proxy
            else:
                # Earlier versions of Selenium use capabilities to pass the settings.
                capabilities = kwargs.get('capabilities', kwargs.get('desired_capabilities'))
                if capabilities is None:
                    capabilities = DesiredCapabilities.FIREFOX
                capabilities = capabilities.copy()
    
                capabilities.update(config)
                kwargs['capabilities'] = capabilities
    
>       super().__init__(*args, **kwargs)
E       TypeError: WebDriver.__init__() got an unexpected keyword argument 'capabilities'

../../.cache/pypoetry/virtualenvs/pyleniumtest-cIp5K4se-py3.11/lib/python3.11/site-packages/seleniumwire/webdriver.py:179: TypeError

I followed the guide and changed nothing else. I only changed the version to latest, because I got a version error.

@ElSnoMan ElSnoMan added the bug Something isn't working label Jun 14, 2023
@ElSnoMan ElSnoMan self-assigned this Jun 14, 2023
@ElSnoMan
Copy link
Owner

I'll take a look and get it fixed. Thanks for the details and for submitting an issue!

@ElSnoMan
Copy link
Owner

ElSnoMan commented Jun 14, 2023

@beu-adesso I think I found the problem! As expected, you did nothing wrong, but there is a simple workaround to keep yo going until I get this fixed and a new version pushed up.

  • As you already did, make sure to add "latest" to the driver.version in pylenium.json
  • Next, open the auto-generated conftest.py and remove or comment out this line from it (Line 257):

image

Let me know if that fixes it for you!

@beu-adesso
Copy link
Author

Yes, thanks this works for me in chrome.
The error in firefox is still there but for starting this helps really.

@ElSnoMan
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants