SeleniumPython Paste Not在無頭模式下工作

Pythonselenium paste在headless模式下不起作用,我嘗試了CONTROL+V、SHIFT+INSERT和pyperclip3、pyperclip、klembord,但似乎什么都不起作用,下面是代碼

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import pyperclip3
import time

Desc = """<p><iframe src="https://www.youtube.com/embed/-grLLLTza6k" frameborder="0" allowfullscreen=""></iframe></p><p><img src="https://images-na.ssl-images-amazon.com/images/I/71Zxjh0AdpL.png" style="width:100%;max-width:450px;clear:both;"></p><p></p><h2>10 Undeniable Reasons People Hate cheats</h2>"""


options = Options()
options.binary_location = r'CHROME_BINARY_LOCATION'
options.add_argument("--headless")
webdriver.Chrome(executable_path=r'CHROME_DRIVER_LOCATION', options=options)
driver.implicitly_wait(10)
driver.get("http://google.com")
time.sleep(2)
pyperclip3.copy(Desc)
element = driver.find_element(By.XPATH, '//input[@name="q"]')
# element.send_keys(Keys.CONTROL, 'v')
a = pyperclip3.paste()
element.send_keys(Keys.SHIFT, Keys.INSERT)
element.send_keys(Keys.CONTROL, 'v')
time.sleep(2)
driver.save_screenshot("image.png")
driver.close()
driver.quit()
? 最佳回答:

我用顯式等待嘗試了下面的代碼,它似乎用pyperclip完成了這項工作:

options = webdriver.ChromeOptions()
options.add_argument("--disable-infobars")
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 2})
options.add_argument('--window-size=1920,1080')
options.add_argument("--headless")
options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(executable_path=driver_path, options = options)
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://google.com")
wait = WebDriverWait(driver, 20)

desc = '''<p><iframe src="https://www.youtube.com/embed/-grLLLTza6k" frameborder="0" allowfullscreen=""></iframe></p><p><img src="https://images-na.ssl-images-amazon.com/images/I/71Zxjh0AdpL.png" style="width:100%;max-width:450px;clear:both;"></p><p></p><h2>10 Undeniable Reasons People Hate cheats</h2>'''
pyperclip.copy(desc)
time.sleep(1)
wait.until(EC.visibility_of_element_located((By.NAME, 'q'))).send_keys(pyperclip.paste())
print("Succesful")
driver.save_screenshot("image.png")

Imports :

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pyperclip as pyperclip
 
主站蜘蛛池模板: 日韩精品一区二区三区中文精品| 波多野结衣一区二区| 国产高清在线精品一区| 精品一区二区三区在线视频观看| 精品三级AV无码一区| 亚洲av一综合av一区| 久久久不卡国产精品一区二区| 国产高清一区二区三区视频| 亚洲一区精彩视频| 无码欧精品亚洲日韩一区夜夜嗨| 中文字幕精品一区影音先锋 | 色窝窝无码一区二区三区| 欧洲精品码一区二区三区免费看 | 2018高清国产一区二区三区| 精品久久一区二区三区| 99久久国产精品免费一区二区| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 久久久久人妻一区精品色| 国模无码一区二区三区不卡| 亚洲性日韩精品国产一区二区| 一本色道久久综合一区| 亚洲av片一区二区三区| 精品久久久久中文字幕一区| 中文字幕一区二区三区精华液 | 精品无码综合一区| 国产美女口爆吞精一区二区| 中文字幕在线视频一区| 国产另类TS人妖一区二区| 日本不卡一区二区三区视频| 无码人妻一区二区三区免费看| 亚欧色一区W666天堂| 亚洲狠狠狠一区二区三区| 精品国产a∨无码一区二区三区| 亚洲欧美日韩中文字幕在线一区| 欧美av色香蕉一区二区蜜桃小说| 麻豆一区二区三区蜜桃免费| 久久久不卡国产精品一区二区| 国产一区韩国女主播| 99国产精品欧美一区二区三区| 国产激情一区二区三区四区| 美女福利视频一区二区|