0

I need to click on a particular button in a Google MyBusiness page. The problem is that no click is happening.

Screenshot shows the button which is supposed to be clicked focused. The html of the element is:

<div role="button" class="U26fgb zg hx mZ r2" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;"
    jsshadow="" jsname="BddwAf" aria-label="Remove" aria-disabled="false" tabindex="0">
    <div class="Ci he" jsname="ksKsZd"></div>
    <content class="gx"><span style="top: -12px"><svg xmlns="https://www.w3.org/2000/svg" width="24" height="24"
                viewBox="0 0 24 24">
                <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
                <path d="M0 0h24v24H0z" fill="none"></path>
            </svg></span></content>
</div>

I have tried to do a wide search for similiar elements with the following selector:

hoursdiv = driver.find_elements_by_xpath('//div[@role = "button"]')
    for el in hoursdiv:
        print(el)
        el.click

Output:

<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-5")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-6")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-7")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-8")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-9")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-10")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-11")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-12")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-13")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-14")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-15")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-16")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-17")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-18")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-19")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-20")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-21")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-22")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-23")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-24")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-25")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-26")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-27")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-28")>
<selenium.webdriver.remote.webelement.WebElement (session="837341007f4b88350c3449e07e291d82", element="0.27450440234933726-29")>

But the element is not getting clicked. The html of the section where these elements are displayed is uploaded here.

enter image description here

3 Answers 3

1

Try to wait until modal window with X buttons appeared and use more specific locator to select buttons:

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

buttons = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, 'div[arial-label="Remove"] svg')))
for button in buttons:
    button.click()
Sign up to request clarification or add additional context in comments.

Comments

1

The element which you are trying to click is a JavaScript enabled element, so you have to induce WebDriverwait for the element to be clickable and you can use either of the following solution:

  • Using CSS_SELECTOR:

    hoursdiv = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div[role='button'][aria-label='Remove']")))
    for el in hoursdiv:
        print(el)
        el.click()
    
  • Using XPATH:

    hoursdiv = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@role='button' and @aria-label='Remove']")))
    for el in hoursdiv:
        print(el)
        el.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
    

Comments

0

I assume wait is not your problem, it need two click, div and <content class="gx">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.