jpjacobpadilla / Google-Colab-Selenium

The best way to use Selenium in Google Colab Notebooks!
https://pypi.org/project/google-colab-selenium/
MIT License
181 stars 20 forks source link

issue with find_element(s) #12

Closed rcs08 closed 3 months ago

rcs08 commented 3 months ago

I want to preface this by saying this is my first time using google_collab_selenium, but I am using your example, so hoping I have not done something basically wrong.

https://colab.research.google.com/drive/1MX3xY23Go1STe7LbDMvwf2KaqHpbrVhC?usp=sharing#scrollTo=vpwUq19kqKqP

I can follow and use driver.get and driver.title, but I cannot get driver.find_element(s) to work (see attached image).

Using "By.ID" produces an error, I have also tried "By.CLASS_NAME" and "by=BY.ID" and get the same error. Is this something I am doing wrong or a issue with find_element(s) 2024-07-21 13_22_56-Google-Colab-Selenium Example Usage - Colab

My end goal is to use selenium to use cookies to access a webpage, or, failing that, use selenium to find the element with the accept button to accept cookies before accessing a webpage.

jpjacobpadilla commented 3 months ago

Thanks for using my project!

From your screenshot and the error message in it, it looks like you just didn't import the "By" object.

Google-Colab-Selenium just sets up Selenium for you, and so to use any other features/objects in Selenium, like the "By" object, you'll need to import them separately from Selenium.

Try something like this:

from selenium.webdriver.common.by import By

driver = gs.Chrome()
driver.get('https://www.google.com')
elements = driver.find_elements(By.XPATH, '//a')
print(len(elements))

driver.quit()

image