2024-09-30 01:34:23 发布
网友
我想使用ChromeDriver在浏览器屏幕中选择一行文本并更改样式。例如,在编辑器工具栏中单击粗体按钮。你知道吗
例如,它是我的html代码。你知道吗
<p id="boldId">bold </p>
我附上了图片。
要创建文本选择、设置格式并获得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>
要创建文本选择、设置格式并获得HTML结果吗?你知道吗
相关问题 更多 >
编程相关推荐