I am trying to click on the profile picture on top right to be able to logout of the website. This is Cisco's license portal website "Logout" link; when you click on the profile picture, it drops down with a "Logout" link.
I can navigate through the body without any issues, but whenever I try to access the header of the site, it fails to find the element.
Using Selenium Chrome driver version 87 with Python
I can't seem to access that Profile Picture highlighted in red in order to logout with chrome selenium driver, it keeps telling me 'Element not found' using the ID or XPATH:
################ Log out ##############################
print('>>> Logging out of Cisco Cloud website')
logout = WebDriverWait(browser, element_timeout,ignored_exceptions=ignored_exceptions)\
.until(EC.presence_of_element_located((By.XPATH, '//*[@id="fwt-profile-button-loggedout"]')))
time.sleep(2)
logout = browser.find_element_by_xpath('//*[@id="fwt-profile-button-loggedout"]')
logout.click()
time.sleep(1)
logout1 = WebDriverWait(browser, element_timeout,ignored_exceptions=ignored_exceptions)\
.until(EC.presence_of_element_located((By.LINK_TEXT, 'Logout')))
time.sleep(2)
logout1 = browser.find_element_by_link_text('Logout')
logout1.click()
time.sleep(5)
------------------
I tried this based on this answer, but still cannot get it to find the element: https://stackoverflow.com/a/48756722/12288943
def expand_shadow_element(element):
shadow_root = browser.execute_script('return arguments[0].shadowRoot', element)
return shadow_root
################# Log out ##############################
print('>>> Logging out of Cisco Cloud website')
logout1 = browser.find_element_by_xpath('//*[@id="overlayBlack"]/csc-header')
shadow_root1 = expand_shadow_element(logout1)
logout2 = browser.find_element_by_xpath('//*[@id="overlayBlack"]/csc-header//div')
shadow_root2 = expand_shadow_element(logout2)
logout = browser.find_element_by_id('fwt-profile-button-loggedout')
time.sleep(2)
logout.click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="overlayBlack"]/csc-header//div"}
(Session info: chrome=87.0.4280.88)