altair-viz / altair_saver

Altair extension for saving charts in a variety of formats.
BSD 3-Clause "New" or "Revised" License
94 stars 32 forks source link

Selenium 4.3.0 has deprecated `find_element_by*()` methods #104

Closed firasm closed 5 months ago

firasm commented 2 years ago

Hi,

Just filing this issue - doing

chart.save() results in this error:

File "scripts/visualize_questions.py", line 61, in <module>
[11](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:12)
    chart.save('images/topics.png',webdriver='firefox',scale_factor=2)
[12](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:13)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair/vegalite/v4/api.py", line 488, in save
[13](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:14)
    result = save(**kwds)
[14](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:15)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair/utils/save.py", line 116, in save
[15](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:16)
    mimebundle = spec_to_mimebundle(
[16](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:17)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair/utils/mimebundle.py", line 60, in spec_to_mimebundle
[17](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:18)
    return altair_saver.render(spec, format, mode=mode, **kwargs)
[18](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:19)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair_saver/_core.py", line 257, in render
[19](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:20)
    mimebundle.update(saver.mimebundle(fmt))
[20](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:21)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair_saver/savers/_saver.py", line 90, in mimebundle
[21](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:22)
    bundle[mimetype] = self._serialize(fmt, "mimebundle")
[22](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:23)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair_saver/savers/_selenium.py", line 284, in _serialize
[23](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:24)
    out = self._extract(fmt)
[24](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:25)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/altair_saver/savers/_selenium.py", line 267, in _extract
[25](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:26)
    driver.find_element_by_id("vis")
[26](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:27)
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
[27](https://github.com/open-resources/physics_bank/runs/7099958015?check_suite_focus=true#step:6:28)
WARNING:tornado.access:404 GET /favicon.ico (127.0.0.1) 0.41ms

The important bit is:

AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'

This seems to have shown up on StackOverflow as well and the fix seems relatively simple. Let me see if I can submit a PR with the fix.

palewire commented 2 years ago

Yup. I got this too.

File ~/.local/share/virtualenvs/news-homepages-Qlfa7zLV/lib/python3.9/site-packages/altair_saver/savers/_selenium.py:267, in SeleniumSaver._extract(self, fmt)
    265 driver.get(url)
    266 try:
--> 267     driver.find_element_by_id("vis")
    268 except NoSuchElementException:
    269     raise RuntimeError(f"Could not load {url}")

AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
palewire commented 2 years ago

This error is now surfacing in Altair's unittests.

mcp292 commented 2 years ago

Workaround:

pip install selenium==4.2.0
rencryptofish commented 1 year ago

Workaround:

pip install selenium==4.2.0

thanks this fixed the issue with altair-saver = "==0.5.0"

soilstack commented 1 year ago

I'm encountering AttributeError: 'Chart' object has no attribute 'get_figure'

altair_saver.__version__ = 0.5.0
selenium.__version__ = 4.8.2.

I'm working inside a conda distribution so attempting to downgrade my selenium fails

conda install selenium=4.2.0 fails:

PackagesNotFoundError: The following packages are not available from current channels:

  - selenium=4.2.0

Current channels:

  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

How can I work around this? I have chrome 110 installed and the correct chromedriver for that version of chrome.

=================

update: conda install selenium=3.141.0 succeeded and now altair-saver is working for me

saiwing-yeung commented 1 year ago

@soilstack Have you specified to use the conda-forge channel? https://anaconda.org/conda-forge/selenium

joelostblom commented 5 months ago

Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.