2

While trying out web scraping at https://store.obeygiant.com/collections/prints/products/obey-ripped-signed-offset-poster, made an attempt to click a button by id and even by name:

browser.find_by_id('AddToCartText').click()
browser.find_by_name('add').click()

But got the following error for either attempt:

selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (657, 724)
  (Session info: chrome=61.0.3163.100)
  (Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.11.6 x86_64)

Tested it out the same way and other sites actually worked.

What could be the issue and what would be a good approach to it?

Thank you in advance and will be sure to vote up and accept answer.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ly Maneug
  • 21
  • 3

1 Answers1

0

This may be happened where after get() elements were not instantly available to click() so to avoid such issues you can use webdriver wait which can check if elements are present and clickable or not after that you can perform click() or any respective operation.

You can use webdriverwait refer.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome("C:\\temp\\chromedriver.exe")
url = r"https://store.obeygiant.com/collections/prints/products/obey-ripped-signed-offset-poster"

driver.get(url)
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "AddToCartText"))) # to check presence of element
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'AddToCartText'))) # to check if element is clickable or not
element.click() # after that  performs click()

driver.close()

Same is applicable for other element only change would be locator.

Mahesh Karia
  • 2,045
  • 1
  • 12
  • 23
  • 1
    Appreciate the response! Before I upvote and accept the answer, gave it a try but got the following error: `AttributeError: 'WebDriver' object has no attribute 'find_element'` for `EC.presence_of_element_located((By.ID, "AddToCartText")))`. Have you actually tried it out with the site? – Ly Maneug Nov 07 '17 at 08:45
  • Checking in to see if you had the chance to take a look. Thank you in advance! – Ly Maneug Nov 07 '17 at 14:59
  • @LyManeug I tested above code which working for me(windows OS) – Mahesh Karia Nov 07 '17 at 16:43