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

AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' #371

Open
ZhouMingjie-code opened this issue Nov 12, 2022 · 4 comments

Comments

@ZhouMingjie-code
Copy link

I want to get more than 100 images. So I try the "chromedriver".
Here is my code:

from google_images_download import google_images_download
response = google_images_download.googleimagesdownload()
arguments = {"keywords":"Michael Jordan","limit":200,"print_urls":True
,"raw_google_data":True,"no_download":True,
"chromedriver":"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"}
paths = response.download(arguments)

Here is the result:
Item no.: 1 --> Item name = Michael Jordan
Evaluating...
Traceback (most recent call last):
File "C:/Users/MJ Zhou/PycharmProjects/SEV/download_image.py", line 8, in
paths = response.download(arguments) #passing the arguments to the function
File "D:\anaconda3\envs\paper1\lib\site-packages\google_images_download-2.8.0-py3.8.egg\google_images_download\google_images_download.py", line 970, in download
File "D:\anaconda3\envs\paper1\lib\site-packages\google_images_download-2.8.0-py3.8.egg\google_images_download\google_images_download.py", line 1111, in download_executor
File "D:\anaconda3\envs\paper1\lib\site-packages\google_images_download-2.8.0-py3.8.egg\google_images_download\google_images_download.py", line 310, in download_extended_page
AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'

How to solve this problem?

@zahiriddin-rustamov
Copy link

zahiriddin-rustamov commented Nov 17, 2022

@ZhouMingjie-code

The find_element function has been changed in the new selenium version, you can find more here

To fix the issue, navigate to the google_images_download.py file then find and change the following:

  1. browser.find_element_by_css_selector("[aria-label='Accept all']").click() change to browser.find_element(By.CSS_SELECTOR, "[aria-label='Accept all']").click()
  2. element = browser.find_element_by_tag_name("body") change to element = browser.find_element(By.TAG_NAME, "body")
  3. browser.find_element_by_xpath('//input[@value="Show more results"]').click() change to browser.find_element(By.XPATH, '//input[@value="Show more results"]').click()

Don't forget to import: from selenium.webdriver.common.by import By

You can also copy-paste the file from here

@livan3li
Copy link

livan3li commented Dec 21, 2022

@ZhouMingjie-code

The find_element function has been changed in the new selenium version, you can find more here

To fix the issue, navigate to the google_images_download.py file then find and change the following:

  1. browser.find_element_by_css_selector("[aria-label='Accept all']").click() change to browser.find_element(By.CSS_SELECTOR, "[aria-label='Accept all']").click()
  2. element = browser.find_element_by_tag_name("body") change to element = browser.find_element(By.TAG_NAME, "body")
  3. browser.find_element_by_xpath('//input[@value="Show more results"]').click() change to browser.find_element(By.XPATH, '//input[@value="Show more results"]').click()

Don't forget to import: from selenium.webdriver.common.by import By

You can also copy-paste the file from here

it still didnt work. Can you help ? One more thing that it is enough to copy google_images_download.py and paste then use it ?
i'ım using ChromeDriver 108.0.5359.71 and Google Chrome 108.0.5359.125

The error i got when i try to run:

Item no.: 1 --> Item name = Man face
Evaluating...
Starting Download...
'NoneType' object is not subscriptable
Traceback (most recent call last):
File "C:/Users/livan/Python_Projects/G_ImagesDownload/DownloadImages.py", line 33, in downloadimages
response.download(arguments)
File "C:\Users\livan\Python_Projects\G_ImagesDownload\lib\site-packages\google_images_download\google_images_download.py", line 971, in download
paths, errors = self.download_executor(arguments)
File "C:\Users\livan\Python_Projects\G_ImagesDownload\lib\site-packages\google_images_download\google_images_download.py", line 1120, in download_executor
arguments) # get all image items and download images
File "C:\Users\livan\Python_Projects\G_ImagesDownload\lib\site-packages\google_images_download\google_images_download.py", line 907, in _get_all_items
object['image_link'], object['image_format'], main_directory, dir_name, count,
TypeError: 'NoneType' object is not subscriptable
python-BaseException

@livan3li
Copy link

livan3li commented Dec 22, 2022

i could sove the problem by creating new project and installed by this command

pip install google_images_download

then i've copied and pasted the changed you've mentioned after that i got another error which is mentioned here and after this it worked.

I used version 108 of chrome and chromedriver, and python 3.6. Thanks for everybody.

@unaboyle
Copy link

@ZhouMingjie-code

The find_element function has been changed in the new selenium version, you can find more here

To fix the issue, navigate to the google_images_download.py file then find and change the following:

  1. browser.find_element_by_css_selector("[aria-label='Accept all']").click() change to browser.find_element(By.CSS_SELECTOR, "[aria-label='Accept all']").click()
  2. element = browser.find_element_by_tag_name("body") change to element = browser.find_element(By.TAG_NAME, "body")
  3. browser.find_element_by_xpath('//input[@value="Show more results"]').click() change to browser.find_element(By.XPATH, '//input[@value="Show more results"]').click()

Don't forget to import: from selenium.webdriver.common.by import By

You can also copy-paste the file from here

@zahir2000's solution above in addition to changing info = data[9] to info = data[23] on line 406 worked for me. Thanks so much for providing the file as well!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants