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.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')"
element = driver.execute_script(js)
print(element)
p = element.find_element_by_xpath("//div[@class='task-grid']")
用xpath试试 常用的几种定位方式试试呢。 一般都是多切换,多尝试
页:
[1]