0

I want to click a rate button of imdb rating buttons but while I trying to click with selenium python it has error :

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="ipc-starbar__rating__button" role="button" aria-label="Rate 2" tabindex="0">...</button> is not clickable at point (848, 472). Other element would receive the click: <div class="ipc-starbar__touch"></div>

if click this element class="ipc-starbar__touch" it have been clicked a rate button of 6

These are the elements :

<button class="ipc-starbar__rating__button" role="button" aria-label="Rate 2" tabindex="0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" class="ipc-icon ipc-icon--star-border ipc-starbar__star ipc-starbar__star--inactive" id="iconContext-star-border" viewBox="0 0 24 24" fill="currentColor" role="presentation"><path fill="none" d="M0 0h24v24H0V0z"></path><path d="M19.65 9.04l-4.84-.42-1.89-4.45c-.34-.81-1.5-.81-1.84 0L9.19 8.63l-4.83.41c-.88.07-1.24 1.17-.57 1.75l3.67 3.18-1.1 4.72c-.2.86.73 1.54 1.49 1.08l4.15-2.5 4.15 2.51c.76.46 1.69-.22 1.49-1.08l-1.1-4.73 3.67-3.18c.67-.58.32-1.68-.56-1.75zM12 15.4l-3.76 2.27 1-4.28-3.32-2.88 4.38-.38L12 6.1l1.71 4.04 4.38.38-3.32 2.88 1 4.28L12 15.4z"></path></svg></button>

I tried many elements like: ipc-starbar__rating__button and '//button[@aria-label="Rate 2"]' in this code:

def rate_movie(self, url, rate=1):
        self.get(url)
        self.maximize_window()
        movie_name = self.find_element(By.CLASS_NAME, 'sc-b73cd867-0.cEmnhL').text
        open_rate = self.find_element(By.XPATH, OPEN_RATE_BTN.format(movie_name))
        open_rate.click()
        sleep(10)
        rate = self.find_element(By.XPATH, RATE_BTN)
        rate.click()
        sleep(20)

I want to click every rate button I want

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
mohammad
  • 21
  • 2

2 Answers2

0

You can try the below code, for 'ElementClickInterceptedException' issue, we can try javascript click() function:

rate_text = driver.find_element(By.XPATH, ".//div[@data-testid='hero-rating-bar__user-rating']/button")
driver.execute_script("arguments[0].click();", rate_text)

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, ".//div[@class='ipc-promptable-base__auto-focus']")))

# selecting the star rating
star_rating = driver.find_element(By.XPATH, ".//div[@class='ipc-starbar__rating']/button[@aria-label='Rate 5']")
driver.execute_script("arguments[0].click();", star_rating)

# clicking Rate button 
driver.find_element(By.CSS_SELECTOR, ".ipc-rating-prompt__rating-container .ipc-btn__text").click()
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • driver.find_element(By.XPATH, ".//div[@data-testid='hero-rating-bar__user-rating']/button").click() this line of code doesn't work : element click intercepted – mohammad Feb 13 '23 at 14:57
  • I executed the code, it is working fine for me, anyway I updated the code with javascript click() function, try this one. – AbiSaran Feb 14 '23 at 02:24
0

To click on the clickable element ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ipc-starbar__rating__button[aria-label='Rate 2']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='ipc-starbar__rating__button' and @aria-label='Rate 2']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352