0

Here is the full code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Edge(executable_path = r"C:\Users\H\Desktop\Automated_Tasks\msedgedriver.exe") # Modify the path here...

# Navigate to URL
driver.get("https://powerusers.microsoft.com/t5/notificationfeed/page")


#accept cookies
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[2]/center/div[1]/div/div[2]/button[1]"))).click()

#click button
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='lia-button lia-button-primary view-more-icon lia-link-ticket-post-action' and @id='viewMoreLink'][contains(@href, 'notificationList')]/span[text()='Show more']"))).click()

The following line:

button=WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "viewMoreLink"))).click()

gives an error:

File C:\Program Files\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py:249 in check_response
    raise exception_class(message, screen, stacktrace)

ElementClickInterceptedException: element click intercepted: Element is not clickable at point (476, 1865)
  (Session info: MicrosoftEdge=109.0.1518.61)

Here is the HTML for the button I'm trying to click.

<a onclick="return LITHIUM.EarlyEventCapture(this, 'click', true)" class="lia-button lia-button-primary view-more-icon lia-link-ticket-post-action" data-lia-action-token="gY01pJ4IhqNcqA8Ouq1d20HgZFI9CVTHrEYgxObqxWantjAxFsOxTacdu8LdHjd0" rel="nofollow" id="viewMoreLink" href="https://powerusers.microsoft.com/t5/notificationfeed/page.notificationlist.notificationlistitems.viewmorelink:viewmore/notificationfeed.lastLoadedTimestamp/1674422253100/notificationfeed.lastViewedTimestamp/1674505573710/container_element/notificationList"><span>Show more</span></a>

Here is a picture showing where the desired element is in:

enter image description here

Jay2454643
  • 15
  • 4
  • hi, can you share the test url? tnx – Manish Jan 23 '23 at 21:40
  • https://powerusers.microsoft.com/t5/notificationfeed/page But you won't be able to access it because it requires one to sign in. Is there another way I can share the source code?. – Jay2454643 Jan 23 '23 at 21:45
  • more that the source code, a working page for the site under test would be more helpful. I created an account but i do not have any notifications – Manish Jan 23 '23 at 21:47
  • Yes you can only get notifications by posting questions, receiving replies etc. – Jay2454643 Jan 23 '23 at 22:16

1 Answers1

0

As per the given HTML to click on the element with text as Show more 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, "a.lia-button.lia-button-primary.view-more-icon.lia-link-ticket-post-action#viewMoreLink[href$='notificationList'] > span"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='lia-button lia-button-primary view-more-icon lia-link-ticket-post-action' and @id='viewMoreLink'][contains(@href, 'notificationList')]/span[text()='Show more']"))).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
    

You can find a relevant detailed discussion in ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks but I tried both options xpath and css but unfortunately both of them did not work. They returned the same error message I was getting before. Do you have any other suggestions? – Jay2454643 Jan 23 '23 at 21:20
  • Check if the desired element is within an [**iframe**](https://stackoverflow.com/a/53276478/7429447) or within a [**shadowRoot**](https://stackoverflow.com/a/73242476/7429447) – undetected Selenium Jan 23 '23 at 21:24
  • Thanks. I've added a picture in the question section showing the hierarchy of the HTML elements. Please see above. I cannot see an Iframe. Also, I'm not too sure about shadowRoot. I don't have any experience with it. – Jay2454643 Jan 23 '23 at 21:35
  • Would you like me to share more images scrolling up? – Jay2454643 Jan 23 '23 at 21:46
  • Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Jan 23 '23 at 21:49