通过python 的selenium 操作shadow前端页面实现自动点击上传图片

通过python 的selenium 操作shadow前端页面实现自动点击上传图片_第1张图片

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = webdriver.Chrome()
url = "https://new.express.adobe.com/tools/convert-to-svg#"
driver.get(url)
time.sleep(20)

#第一步
shadow_root_qa_app = driver.execute_script("return document.querySelector('x-app').shadowRoot.querySelector('x-quick-action-tools-view').shadowRoot.querySelector('quick-action-component').shadowRoot.querySelector('qa-app-root')")

#第二步
qa_app_element = shadow_root_qa_app.find_element(By.TAG_NAME, 'qa-app')
#第三步
qa_convert_element = qa_app_element.find_element(By.TAG_NAME, 'qa-convert-to-svg-editor')
#第四步
qa_workspace_element = driver.execute_script("return arguments[0].shadowRoot.querySelector('qa-workspace')", qa_convert_element)
#第五步
qa_file_upload_element = qa_workspace_element.find_element(By.TAG_NAME, 'qa-file-upload')
#第六步
sp_dropzone_element = driver.execute_script("return arguments[0].shadowRoot.querySelector('sp-dropzone')", qa_file_upload_element)
#绑定点击事件
sp_dropzone_element.click()
#click_shadow = qa_convert_element.execute_script("return document.querySelector('qa-workspace')")

time.sleep(100)

你可能感兴趣的:(python,selenium,前端)