gpt4 book ai didi

python - ActionChains 中的 perform() 和 reset_actions() 不起作用 selenium python

转载 作者:行者123 更新时间:2023-12-04 04:31:08 24 4
gpt4 key购买 nike

这是没有错误的代码:
perform() 和 reset_actions()
但这两个功能必须结合使用

import os
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import random

# Setting the chrome_options
global chrome_options
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--profile-directory=Default')
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument('disable-infobars')
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])

google_search = [
"1.' driver.switch_to.active_element' ",
"2.this code is a one of important snippet for facebook automation.",
]

random_google_search = random.choice(google_search)

# Setting the Chrome Driver
global driver
driver = webdriver.Chrome("chromedriver.exe", chrome_options=chrome_options)

# Setting the Actions
global actions
actions = ActionChains(driver)


#the loop Running
def navigation():
time.sleep(5)
actions.reset_actions()

driver.get("https://google.com")

actions.send_keys(random_profile_post)

total_tab = 3
sleep_time = 1
implicitly_wait_time = 4

actions.reset_actions()
driver.implicitly_wait(implicitly_wait_time)
time.sleep(sleep_time)

for i in range(total_tab):
actions.send_keys(Keys.TAB)
print("Pressing * " + str(i + 1) + " * No Tab")

actions.send_keys(Keys.ENTER)
actions.perform()


for i in range(10):
navigation()
print("Pressing * " + str(i + 1) + " * st navigation function")
我正在与 一起工作导航()职能:
在循环区
actions.send_keys(Keys.TAB)
actions.reset_actions()
我需要重置操作,但它不会重置以前的 preform()
什么是击球手的方式来做到这一点。
Please watch the youtube video for more clear understanding.

最佳答案

该问题已经修复,但将在下一个版本中出现。检查问题 #6837在 github 中。
现在您可以使用临时解决方案。

def perform_actions():
""" Perform and reset actions """
actions.perform()
actions.reset_actions()
for device in actions.w3c_actions.devices:
device.clear_actions()


# the loop Running
def navigation():
time.sleep(5)

driver.get("https://google.com")

actions.send_keys("A")

total_tab = 4
sleep_time = 1
implicitly_wait_time = 4

# actions.reset_actions()
driver.implicitly_wait(implicitly_wait_time)
time.sleep(sleep_time)

for i in range(total_tab):
actions.send_keys(Keys.TAB)
print("Pressing * " + str(i + 1) + " * No Tab")

actions.send_keys(Keys.ENTER)
perform_actions()
print()

关于python - ActionChains 中的 perform() 和 reset_actions() 不起作用 selenium python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67614276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com