Home > Back-end >  Element <div class="form-group__checkbox">...</div> is not clickable at point
Element <div class="form-group__checkbox">...</div> is not clickable at point

Time:06-27

I tried to build a code to repeat the search on a website. I follow a number of method from the forum but still failed to resolve the below issue. Below error message was popped up when I tried to click the checkbox "Ensuite". See if anyone knows how to resolve it.

Error Message selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (323, 690). Other element would receive the click: ...

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
web = webdriver.Chrome()
url = 'https://www.spareroom.co.uk/flatshare/search.p'
wait = WebDriverWait(web, 20)
web.get(url)
wait.until(EC.element_to_be_clickable((By.ID, 'onetrust-accept-btn-handler'))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.panel-tab > a:nth-child(2)'))).click()
web.find_element(By.ID, "search_by_location_field").clear()
web.find_element(By.ID, "search_by_location_field").send_keys("KT5")
web.find_element(By.ID,"search-button").click()
web.maximize_window()

#To check the "Ensuite" checkbox ==> failed to select the option and with error
wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/div[1]/div[1]/section[7]/div[3]/div[1]'))).click()

#To click the button "Apply filters" 
wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/div[1]/div[1]/div[1]/div[1]/button[1]'))).click()

CodePudding user response:

It looks you are using the absolute path that causing the error

Use the below xpath to click on Yes for Ensuite checkbox

//input[@id='en-suite']

Your code will be like

wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='en-suite']"))).click()

OR

wait.until(EC.element_to_be_clickable((By.XPATH, "//label[@title='Only show rooms with an En-suite bathroom']"))).click()

CodePudding user response:

To make it work, I used enter image description here

CodePudding user response:

Finally, I solve the problem by ensuring the checkbox "Ensuite" is visible on the screen before I trigger the click. To do this, I have to locate an element and then trigger the key "PAGE_DOWN" first. It works but is very dumb.
*************************** wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/section[1]/div[1]/div[3]/input[1]'))).send_keys(Keys.PAGE_DOWN) ****************************

Below are the complete code for reference. However, I found it may not work every time.

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

web = webdriver.Chrome()
url = 'https://www.spareroom.co.uk/flatshare/search.p'
wait = WebDriverWait(web, 20)
web.get(url)
wait.until(EC.element_to_be_clickable((By.ID, 'onetrust-accept-btn-handler'))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.panel-tab > a:nth-child(2)'))).click()
web.find_element(By.ID, "search_by_location_field").clear()
web.find_element(By.ID, "search_by_location_field").send_keys("KT5")
web.find_element(By.ID,"search-button").click()
web.maximize_window()

web.find_element(By.ID, "maxRent").send_keys("900")

# press page down in order to ensure "Ensuite" checkbox is visuable before click the checkbox
wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/section[1]/div[1]/div[3]/input[1]'))).send_keys(Keys.PAGE_DOWN)
# To check the "Ensuite" checkbox
wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/div[1]/div[1]/section[7]/div[3]/div[1]'))).click()

# To click the button "Apply filters"
wait.until(EC.element_to_be_clickable((By.XPATH, '/html[1]/body[1]/main[1]/div[2]/aside[1]/form[1]/div[1]/div[1]/div[1]/div[1]/button[1]'))).click()
web.find_element(By.ID, "sort_by").send_keys("Newest Ads")
  • Related