I am trying to do logout on a web page by selenium and python, and currently no luck. In order to do a logout, I need to click the link at the upper right corner of the web page, and it will have a small drop-down window open, and then I can click the "logout" icon inside this drop-down window. Here is the picture of this drop down window.
And the inspect code for this logout icon in the dropdown window.
Now in my python code, I was able to have the drop-down window open, but if I was to click the logout icon, I keep getting exception of "selenium.common.exceptions.ElementNotVisibleException".
Here is my code:
try:
# to click the link so that the drop-down window opens
action = ActionChains(self.driver)
dropdownwindow= self.driver.find_element_by_xpath("//span[@class='ssobanner_logged']/img")
action.move_to_element(dropdownwindow).perform()
dropdownwindow.click()
# try to click the logout icon in the drop-down so that user may logout
logoutLink = self.driver.find_element_by_xpath(
"//*[@id='ctl00_HeaderAfterLogin1_DL_Portals1']/tbody/tr/td[4]/a/img")
action.move_to_element(logoutLink).perform()
logoutLink.click()
return True
except Exception as e:
self.logger.info(e)
raise
return False
And I have got such exceptions during the run time.
selenium.common.exceptions.NoSuchElementException:
Message: no such element: Unable to locate element:
{"method":"xpath","selector":"//*[@id='ctl00_HeaderAfterLogin1_DL_Portals1']/tbody/tr/td[4]/a/img"}
Does anyone know a better way to handle that, other than the xpath I was using ?