0

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?

Sht
  • 179
  • 1
  • 1
  • 9
  • Before, trying to interact with the element put a time.sleep(certain_time). This will give the element time to load. Though this is not the best practice so take a look here https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable – Buddy Bob Apr 05 '21 at 18:44
  • But this gives me another error: – Sht Apr 05 '21 at 19:49
  • An that error is? – Buddy Bob Apr 05 '21 at 19:50
  • `WebDriverWait(driver, 4).until(EC.presence_of_element_located((By.XPATH, "//li[@class='style__CategoryItem-sc-8ncu0g-2 tZtCz']//span[text()='%s']" %(aaa[1])))).click()` `TimeoutException: Message: ` – Sht Apr 05 '21 at 19:51

1 Answers1

1

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()
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44
  • still the same error: `TimeoutException: Message:` even I tried all of the waiting options – Sht Apr 05 '21 at 20:00
  • This worked perfectly for me! Thanks for putting your time into providing this answer! Solved my problem of sequencing in a Javascript application within a Spyder IDE. – Bradley Thomas Anderson Jan 05 '23 at 05:38