您想创建文本选择、设置格式并获得 HTML 结果吗?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://haixing-hu.github.io/vue-html-editor/demo.html")
editable = driver.find_element_by_xpath('//div[@class="note-editable panel-body"]')
buttonBold = driver.find_element_by_xpath('//button[@data-name="bold"]')
buttonItalic = driver.find_element_by_xpath('//button[@data-name="italic"]')
actions = webdriver.ActionChains(driver)
actions.move_to_element(editable)
actions.click()
actions.send_keys(Keys.CONTROL + 'a')
actions.click(buttonBold)
actions.click(buttonItalic)
actions.perform()
print('HTML Source:')
print(editable.get_attribute('innerHTML'))
# <span style="font-weight: bold; font-style: italic;">Hello World!</span>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句