Browse Source

MOD:优化长文本输入时间

cxyu 3 năm trước cách đây
mục cha
commit
aee1073a6e
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      wechat_action/create_ad_layout.py

+ 4 - 2
wechat_action/create_ad_layout.py

@@ -1,6 +1,7 @@
 from selenium.webdriver.support.wait import WebDriverWait
 from selenium.webdriver.common.keys import Keys
 from selenium.webdriver import ActionChains
+import pyperclip
 from logging import handlers
 import logging
 import requests
@@ -364,7 +365,6 @@ class CreateAd:
         logging.info('图片模块设置结束')
 
     def set_content(self, config_info):
-        # TODO:长文本需要优化输入时间
         logging.info(' 开始设置文本模块')
         # 设置文本模块
         # 1.文本内容2.文本颜色3.是否加粗4.文本位置设置5.文本大小
@@ -373,9 +373,10 @@ class CreateAd:
         self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[5]/div/div').click()
         time.sleep(random.uniform(0.2, 0.3))
         input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
+        pyperclip.copy(config_info['text'])
         for _ in input_elements:
             if _.is_enabled() and _.is_displayed():
-                _.send_keys(config_info['text'])
+                _.send_keys(Keys.CONTROL, 'v')
 
         # 设置颜色
         if config_info['color'] != '#595959':
@@ -710,6 +711,7 @@ class CreateAd:
 
     def create_layout(self, layout, err_num=0):
         #
+
         try:
             self.send_file_alone(layout)
             self.set_advertisement_sign(layout_name=layout['layoutName'])