我正试图点击右上角的个人资料图片,以便能够注销该网站。 这是思科的许可证门户网站“注销”链接;当你点击个人资料图片时,它会随着一个“注销”链接而下降
我可以在正文中导航,没有任何问题,但是每当我尝试访问站点的标题时,它都找不到元素
将Selenium Chrome驱动程序版本87与Python一起使用
为了使用chrome selenium驱动程序注销,我似乎无法访问以红色突出显示的配置文件图片,它不断使用ID或XPATH告诉我'Element not found':
################ 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)
------------------
我根据这个答案尝试了这个方法,但仍然无法找到元素: 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)
在
'csc-header'
标记内有一个#shadow-root(0)
。您尝试访问的元素位于阴影根中。我想这就是为什么你会得到一个'Element not found'
错误。你必须先导航到阴影中。希望这能为你指明正确的方向相关问题 更多 >
编程相关推荐