Forums

Selenium not working

Hi everyone!

Can i get some help with running Selenium please ? I have followed the instructions on the selenium FAQ page. I am currently on Python = 3.10 Selenium 4.7.2

def data_place_crawler():


  chrome_options = webdriver.ChromeOptions()
  chrome_options.add_argument("--no-sandbox")
  chrome_options.add_argument("--headless")
  chrome_options.add_argument("--disable-gpu")
  driver = webdriver.Chrome(options=chrome_options) #line 23 - 24 for hosting test

  try:
      dfPlace = []


      #time.sleep(100)
      foodID_list =[]
      businessName_list =[]
      url_list =[]

      food_list = (pd.read_csv("place_url.csv")['foodid'])
      placeURL_list = (pd.read_csv("place_url.csv")['placeURL'])
      foodPlace_dict = dict(zip(food_list, placeURL_list))

      for food, url in foodPlace_dict.items():
          driver.get(url)
          time.sleep(3)

          #Find scroll layout
          scrollable_div = driver.find_element(By.XPATH, '//* 
                                             [@id="QA0Szd"]/div/div/div[1]/div[2]/div/div[1]/div/div/div[2]/div[1]')
          #Scroll as many times as necessary to load all reviews
          for i in range(0,2):
                  driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight',
                          scrollable_div)
                  time.sleep(3)


          businessDetail = driver.find_elements(By.CLASS_NAME, "hfpxzc")

          for lnk in businessDetail:
              foodID_list.append(food)
              businessName_list.append(lnk.get_attribute('aria-label'))
              url_list.append(lnk.get_attribute('href'))

      df = pd.DataFrame(list(zip(foodID_list,businessName_list, url_list)),
                      columns=['Food ID','Business Name', 'URL Link'])

      print(df)
      df.to_csv('/home/smtan041/FYP/google_place.csv',index=False)

      dfPlace = df.values.tolist()
      messageComplete = "Completed!"

      return dfPlace , messageComplete
  finally:
      driver.quit()

But when I check my logs all I got was :

 Incompatible release of chromedriver (version 90.0.4430.24) detected in PATH: /usr/local/bin/chromedriver

I do not have a local chromedriver being used, so I can get some guidance how to get this running ?

My most sincere thanks in advance, Smtan041

I can't reproduce that behavior -- could you provide us with more details: where are you running the code on PA? Is default code snippet from the help page working for you? Could you double check that you're using selenium version 4.7.2 (I'm guessing that you're running the code in a virtual env, so you can run pip show selenium when the venv is activated to confirm the installed version).

Hi, I tried with 4.7.2 but it still cannot work. I will be trying the default code snippet and will update again.

15:37 ~/FYP (master)$ pip show selenium
Name: selenium
Version: 4.7.2
Summary: 
Home-page: https://www.selenium.dev
Author: 
Author-email: 
License: Apache 2.0
Location: /home/smtan041/.local/lib/python3.10/site-packages
Requires: certifi, trio, trio-websocket, urllib3
Required-by: 
15:38 ~/FYP (master)$

Did you install your own Chromium?

I'm also having this problem, I've tryed uploading a new version of chrome driver and setting the path to it. but it still get this old chrome driver from the local folder, but there's nothing there...

You'll both want to use the preinstalled version of chromedriver as it matches the installed version of the Chrome browser

It's at the path /usr/local/bin/chromedriver, but selenium should find it by itself if its the only version on the path

@sboyd

I worked, changed the path to:

chrome_driver_path = '../../usr/local/bin/chromedriver'

I also needed to use: options.add_argument('--no-sandbox')

One thing tho... I need to sign in to google and the chromium doesn't seem to support js. So I can't do it.

chromium does support js, but it's likely that Google have protections against logging in with automated tools.