selenium xpath unable to identify click on web page


I am trying to click on the rate button to set the rating for the movie Mona Lisa and the Blood Moon on the IMDB website as illustrated by the image further below.

I have tried various combinations of selenium xpath values and have googled various links to attempt to achieve this, but can’t remember which now. My current python is below less logging onto the IMDB website to be able to effect this new rating.

wait = WebDriverWait(driver, 20)

xpath = "(//div[@data-testid='hero-rating-bar__user-rating'])[1]//button"
wait.until(EC.element_to_be_clickable((By.XPATH, xpath))).click()

xpath = "//button[@aria-label='Rate 1']//svg"
wait.until(EC.element_to_be_clickable((By.XPATH, xpath))).click()

The first click works as I want; but the second fails. The HTML I’m trying to scrape is below:

<div class="ipc-starbar">
    <div class="ipc-starbar__touch"></div>
    <div class="ipc-starbar__rating">
        <button class="ipc-starbar__rating__button" role="button" aria-label="Rate 1" tabindex="0">
            <svg >question before; but that was pertaining to an episode of a series, which has a completely different setup of HTML

I tried clicking the button above to set the rating to one; but my python crashed complaining that the button was unclickable.

enter image description here

Asked By: Cyrus


Try to click the stars using Javascript executor, it is working:

stars = driver.find_element(By.XPATH,"(//*[@class='ipc-starbar__rating']/button)[1]")
driver.execute_script("arguments[0].click();", stars)

If you want to give more ratings change in number '1' in the xpath to whatever you want up to '10'

Answered By: AbiSaran