峰大爷
2022-01-17 15:59
采纳率: 86.7%
浏览 107

selenium.webdriver.remote.webelement.WebElement 和shadow-root定位问题


def get_id(driver):
    driver.get('chrome://extensions/')
    shadow = driver.find_element(By.XPATH,'//extensions-manager')
    shadowroot = get_shadow(shadow,driver)
    shadow1 = shadowroot.find_element_by_xpath('//*[@id="items-list"]')
def get_shadow(ele,driver):
    shadow_root = driver.execute_script('return arguments[0].shadowRoot', ele)
    return shadow_root
if __name__ == '__main__':
    options = Options()
    options.add_argument("--user-data-dir=" + r"C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/")
    driver = uc.Chrome(options, version_main=96)
    username = 'pierrelattimer53@gmail.com'
    password = 'asyufguia646'
    secret = '7vqx4dzbp35un7xllg6mm7dy'
    # get_exe(driver,username,password,secret)
    get_id(driver)


js = "return document.getElementsByTagName('iframe')[4]"
        element = driver.execute_script(js)
        print(element)
        p = element.find_element_by_xpath("//div[@class='task-grid']")

2条回答 默认 最新

相关推荐 更多相似问题