SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.85k stars 8.22k forks source link

[🐛 Bug]: Conda Python Selenium 4.27.0 missing remote/getAttribute.js and other js files #14826

Open JwDLR opened 2 days ago

JwDLR commented 2 days ago

What happened?

I have updated my Conda environment and upgraded to selenium 4.27. When running my test, I get an error that the js files are missing in selenium/webdriver/remote. I went back to 4.26 and the error is gone or the files are back. Under 4.27 there are only .py files in the remote subfolder.

How can we reproduce the issue?

# -*- coding: utf-8 -*-

# to controll the firefox browser
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

serv = FirefoxService(GeckoDriverManager().install())
driver = webdriver.Firefox(service=serv)

driver.get("https://www.dlr.de/de")

menu_item = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(
    (By.XPATH, "/html/body/div[2]/div[3]/div/div/nav/div/ul/li[1]/button")))
ActionChains(driver).move_to_element(menu_item).perform()  # hover

Relevant log output

Verbunden mit selenium (Python 3.11.10)

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File \\as-exv-balu0\EXV_User\JWagner\Gitlab\gleitzeit2zeitnachweis\gleitzeit copy.py:17
     13 driver = webdriver.Firefox(service=serv)
     15 driver.get("https://www.dlr.de/de")
---> 17 menu_item = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(
     18     (By.XPATH, "/html/body/div[2]/div[3]/div/div/nav/div/ul/li[1]/button")))
     19 ActionChains(driver).move_to_element(menu_item).perform()  # hover

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\site-packages\selenium\webdriver\support\wait.py:96, in WebDriverWait.until(self, method, message)
     94 while True:
     95     try:
---> 96         value = method(self._driver)
     97         if value:
     98             return value

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\site-packages\selenium\webdriver\support\expected_conditions.py:156, in visibility_of_element_located.<locals>._predicate(driver)
    154 def _predicate(driver: WebDriverOrWebElement):
    155     try:
--> 156         return _element_if_visible(driver.find_element(*locator))
    157     except StaleElementReferenceException:
    158         return False

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\site-packages\selenium\webdriver\support\expected_conditions.py:179, in _element_if_visible(element, visibility)
    178 def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[Literal[False], WebElement]:
--> 179     return element if element.is_displayed() == visibility else False

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webelement.py:258, in WebElement.is_displayed(self)
    256 # Only go into this conditional for browsers that don't use the atom themselves
    257 if isDisplayed_js is None:
--> 258     _load_js()
    259 return self.parent.execute_script(f"/* isDisplayed */return ({isDisplayed_js}).apply(null, arguments);", self)

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webelement.py:48, in _load_js()
     46 global isDisplayed_js
     47 _pkg = ".".join(__name__.split(".")[:-1])
---> 48 getAttribute_js = pkgutil.get_data(_pkg, "getAttribute.js").decode("utf8")
     49 isDisplayed_js = pkgutil.get_data(_pkg, "isDisplayed.js").decode("utf8")

File c:\Users\my_user\AppData\Local\miniforge3\envs\selenium\Lib\pkgutil.py:640, in get_data(package, resource)
    638 parts.insert(0, os.path.dirname(mod.__file__))
    639 resource_name = os.path.join(*parts)
--> 640 return loader.get_data(resource_name)

File <frozen importlib._bootstrap_external>:1130, in get_data(self, path)

FileNotFoundError: [Errno 2] No such file or directory: 'c:\\Users\\my_user\\AppData\\Local\\miniforge3\\envs\\selenium\\Lib\\site-packages\\selenium\\webdriver\\remote\\getAttribute.js'

Operating System

Windows 10

Selenium version

Python 3.11 and 3.12

What are the browser(s) and version(s) where you see this issue?

Firefox 128.3.1esr

What are the browser driver(s) and version(s) where you see this issue?

webdriver-manager 4.0.2

Are you using Selenium Grid?

No response

github-actions[bot] commented 2 days ago

@JwDLR, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

navin772 commented 2 days ago

Hi @JwDLR, I am not able to reproduce this error and the code works fine on my system. Can you reinstall selenium or upgrade to 4.27.1?

JwDLR commented 2 days ago

I can reproduce the error on a second computer

conda create -n seleniumTest python=3.11 conda-forge::selenium=4.27 4.27.1 is not yet available via conda forge

Probably it's a Conda Forge problem. 4.27 is only a third of the size of the previous updates. I unpacked it manually and the js. files are also missing. Please see here

But when I install Selenium in a conda environment using pip, the files are there

pip install selenium

navin772 commented 2 days ago

I didn't use conda-forge to install selenium, but yes the size is reduced to 1/3 as compared to previous ones.

@VietND96 can this be an issue due to the recent pyproject.toml changes? I am not entirely sure about this since chances of something going wrong at conda's end are minimal.

cc: @AutomatedTester

VietND96 commented 2 days ago

I suspect it relates to the support of Conda, which I can find https://github.com/conda/conda/issues/10633, https://github.com/conda/conda/issues/12462 Recently, setuptools config moved to pyproject.toml from setup.py Can you try to read this to see any help https://stackoverflow.com/questions/76722680/what-is-the-best-way-to-combine-conda-with-standard-python-packaging-tools-e-g

VietND96 commented 2 days ago

I am not sure how conda-forge::selenium is created and published. Look around if you can raise an issue to them. I can see https://pypi.org/project/python-wheel-to-conda-package/, probably can try to get wheel file from https://pypi.org/project/selenium/4.27.1/#files and convert it to Conda package, or try to do it yourself in local.