0

I have just started to learn python and tried to make a little project where I do some interaction with a website, but I have a little problem and I am not able to solve it myself.

I am trying to find some stuff on a website. Therefore I enter some criteria and press then the search button. If my search is successful, new information appears on the website and I would like to hit a button, do some other actions and go back to the search side. If there is no result, I go back to the search site.

The code works fine for most of the time, but sometimes I receive an error and my code interrupts.

#click search button
css = 'button.btn-standard:nth-child(2)'
iElement = browser.find_element_by_css_selector(css)
iElement.click()

#wait some time
t = random.uniform(0.190, 0.25)
time.sleep(t)
        
css = 'body > main > section > section > div.ut-navigation-container-view--content > div > div > section.ut-navigation-container-view.ui-layout-right > div > div > div.DetailPanel > div.bidOptions > button.btn-standard.buyButton.currency-coins'
try:            
  #Check if search is successful
  iElements = browser.find_element_by_css_selector(css)

  #Buy now for n coins
  iElement = browser.find_element_by_css_selector(css)
  iElement.click() # <- here is were the error occurs

  .... some other code that works...          
except NoSuchElementException:
  a = 1

#Go back
css = '.ut-navigation-button-control'
iElement = browser.find_element_by_css_selector(css)
iElement.click()

Error: ElementClickInterceptedException: Message: Element is not clickable at point (972,569) because another element obscures it

I have already tried element_to_be_clickable but I was not able to handle it.

Can somebody help me with my problem?

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Andi
  • 1
  • 2
  • What is the error you are getting? Please add the whole error to your original post so it is easier for others to help you. And what does it mean that you were not able to handle element to be clickable? – Mate Mrše Oct 13 '20 at 08:01
  • You have exact error "Element is not clickable at point" so You must watch how elements are displayed on the page, maybe one obscures Your element that You want click. Do You have problem with meaning "obscures"?. We cannot help You without knowing target page structure. – Jakub Ujvvary Oct 13 '20 at 08:01
  • @MateMrše The complete error message is: ElementClickInterceptedException Traceback (most recent call last) in 74 print('Treffer bei Suche-Nr:', i+1) 75 iElement = browser.find_element_by_css_selector(css) ---> 76 iElement.click() .... ElementClickInterceptedException: Message: Element – Andi Oct 13 '20 at 12:54

2 Answers2

0

An element is overlapping your element try using this instead.

driver.execute_script("arguments[0].click();",  iElement)

To wait and click on it

iElement=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, css)))

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
  • I guess I have not done it correct, because I still get an error ```#Buy now for n coins #iElement = browser.find_element_by_css_selector(css) #iElement.click() iElement = WebDriverWait(browser, 2).until(ec.element_to_be_clickable((By.CSS_SELECTOR, css))) browser.execute_script("arguments[0].click();", iElement) iElement.click()``` Without iElement.click() there is no error, but the button will not be clicked – Andi Oct 14 '20 at 07:22
  • Remove the second click and increase time. – Arundeep Chohan Oct 14 '20 at 07:58
0

So, an element with class "ut-click-shield" is blocking the click, as the name implies. There are some things you can try:

a) Add a "wait for element clickable" before actually clicking the element:

iElement = WebDriverWait(browser, 20).until(expected_conditions.element_to_be_clickable((By.CSS, "myElement"))).click()

b) Another option is using Actions Chain:

ActionChains(browser).move_to_element((By.CSS, "myElement")).click().perform()

c) For an overview of different "Element not clickable" reasons see this discussion.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • still get the same error if I use ```#Buy now for n coins #iElement = browser.find_element_by_css_selector(css) #iElement.click() iElement = WebDriverWait(browser, 2).until(ec.element_to_be_clickable((By.CSS_SELECTOR, css))).click()``` – Andi Oct 14 '20 at 07:28
  • You set the timeout to 2 seconds. Have you tried with a longer timeout? – Mate Mrše Oct 14 '20 at 07:37
  • If you found it useful, please accept and/or upvote my answer. – Mate Mrše Oct 14 '20 at 14:36