Sht
Sht

Reputation: 189

Selenium code that works in python/spyder does not works in colab

I am using selenium in Python and Colab. I have some code that works in spyder, extracts elements but gives me error in collab

NoSuchElementException: Message: no such element: Unable to locate element:

What is a possible explanation and is it possible to fix this problem?

Upvotes: 0

Views: 294

Answers (1)

Buddy Bob
Buddy Bob

Reputation: 5889

Try using this method of waiting before an element Is accessed.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
driver = webdriver.Chrome(executable_path='path')            
waitshort = WebDriverWait(driver,.5)
wait = WebDriverWait(driver, 20)
waitLonger = WebDriverWait(driver, 100)
visible = EC.visibility_of_element_located        
driver.get('website')
element = wait.until(visible((By.XPATH,'element_xpath'))).click()

Upvotes: 1

Related Questions