0

I am new to python and I trying to scrape all the recent activity of a Linkedin user for the past 6 months . The code below works fine when there is no video liked by the user. If there is a video, then I get ElementClickInterceptedException error. Could you please suggest a solution for this?

Code:

for elem in driver.find_elements_by_xpath('.//a/div/span/span[@class = "visually-hidden"]|.//a/div/span/span/span[@class = "visually-hidden"]'):
    if elem.text == "7 months ago":
        break
    else:
        print(elem.text)
        try:
            print ("in try")
            button["key%s" %i] = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//*[@id='main']/div/div[2]/div/span/button[@class='artdeco-button artdeco-button--muted artdeco-button--1 artdeco-button--full artdeco-button--secondary ember-view']")))
            hover = ActionChains(driver).move_to_element(button.get("key%s" %i))
            hover.perform()
            button.get("key%s" %i).click()
            i = i+1
        except exceptions.StaleElementReferenceException as e:
            element = driver.find_element_by_xpath("//*[@id='main']/div/div[2]/div/span/button[@class='artdeco-button artdeco-button--muted artdeco-button--1 artdeco-button--full artdeco-button--secondary ember-view']")
            driver.execute_script("arguments[0].click();", element)
            print(e)

This is the error displayed:

ElementClickInterceptedException at /login/
Message: element click intercepted: Element <button tabindex="-1" id="ember631" class="artdeco-button artdeco-button--muted artdeco-button--1 artdeco-button--full artdeco-button--secondary ember-view" type="button">...</button> is not clickable at point (249, 547). Other element would receive the click: <img width="600" src="https://media-exp1.licdn.com/dms/image/C4E22AQHboa3Imyqsew/feedshare-shrink_800/0/1619094377786?e=1622678400&amp;v=beta&amp;t=oa-7gYnDMsfdopCC30LWGu4sv2R8TLPN6drB_Q5IQME" loading="lazy" height="750" alt="No alternative text description for this image" id="ember902" class="ivm-view-attr__img--centered feed-shared-image__image feed-shared-image__image--constrained lazy-image ember-view">

Thanks in advance!

  • Does this answer your question? [Debugging "Element is not clickable at point" error](https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error) – Prophet May 03 '21 at 08:03
  • Yes... Very much. Thanks and sorry for the delay in response. – Pooja Vadiraja May 27 '21 at 14:10

1 Answers1

0

Instead of

button["key%s" %i] = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//*[@id='main']/div/div[2]/div/span/button[@class='artdeco-button artdeco-button--muted artdeco-button--1 artdeco-button--full artdeco-button--secondary ember-view']")))

try using visibility_of_element_located expected condition i.e.

button["key%s" %i] = WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='main']/div/div[2]/div/span/button[@class='artdeco-button artdeco-button--muted artdeco-button--1 artdeco-button--full artdeco-button--secondary ember-view']")))

In case this is still doesn't help put a small sleep time.sleep(1) after this line before clicking on the element

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Thanks. I tried the above. I have received the following exception:Message: stale element reference: element is not attached to the page document – Pooja Vadiraja May 02 '21 at 19:20
  • Possibly it's dynamic DOM page there. In this case you have no simple and stable way, only adding some hardcoded delay like `time.sleep(1)` AFTER `visibility_of_element_located` fulfilled and then, after the sleep put `visibility_of_element_located` again and after that click the element. Let me know if it works now – Prophet May 02 '21 at 19:25