Skip to content

selenium.webdriver.common.options is missing #7379

Closed

Description

@bersbersbers

See https://github.com/python/typeshed/tree/master/stubs/selenium/selenium/webdriver/common

While the following codes are running fine:

"""Show bug."""
from typing import Any, Literal, Type

from selenium import webdriver
from selenium.webdriver import chrome, firefox
from selenium.webdriver.common.options import ArgOptions
from selenium.webdriver.remote.webdriver import WebDriver


def fun(browser: Literal["chrome", "firefox"]) -> Any:
    """Show bug."""
    driver_class: Type[WebDriver]
    options: ArgOptions
    if browser == "chrome":
        driver_class = webdriver.Chrome
        options = chrome.options.Options()
    elif browser == "firefox":
        driver_class = webdriver.Firefox
        options = firefox.options.Options()
    return (driver_class, options)
"""Show bug."""
from selenium.webdriver import chrome
from selenium.webdriver.common.options import ArgOptions


def fun() -> ArgOptions:
    """Show bug."""
    return chrome.options.Options()

I see various errors in Pylance and mypy:

Import "selenium.webdriver.common.options" could not be resolved
Incompatible types in assignment (expression has type "Options", variable has type "ArgOptions")
Incompatible return value type (got "Options", expected "ArgOptions") [return-value]

Interstingly, selenium.webdriver.common.options is not mentioned here, either: https://www.selenium.dev/selenium/docs/api/py/api.html#webdriver-common

Activity

  1. added
    stubs: incompleteAnnotations or sub-modules missing from an existing package or module
    on Feb 25, 2022
  2. Akuli commented on Feb 25, 2022

    @Akuli
    Collaborator

    Are you using Selenium 3 or Selenium 4? If it is Selenium 4, you should upgrade to 4.1.2 (released yesterday). It comes with its own type annotations, and type checkers should use those instead of what's in typeshed.

  3. bersbersbers commented on Feb 25, 2022

    @bersbersbers
    ContributorAuthor

    Are you using Selenium 3 or Selenium 4? If it is Selenium 4, you should upgrade to 4.1.2 (released yesterday). It comes with its own type annotations, and type checkers should use those instead of what's in typeshed.

    Thanks for the hint! I was using some version Selenium 4 (installed 3-4 days ago), and due to some typing error that I don't remember, I installed types-selenium without paying attention to the version number (3.141.7). I then updated to selenium==4.1.2 today. I guess that version (and maybe the previous one, not sure) conflict with the older types-selenium, uninstalling which solves the issue. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: incompleteAnnotations or sub-modules missing from an existing package or module

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions