【发布时间】:2021-05-20 05:05:40
【问题描述】:
这是没有错误的代码:
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")
我正在使用 navigation() 函数:
在循环区
actions.send_keys(Keys.TAB)
actions.reset_actions()
我需要重置操作,但它没有重新安装以前的 preform()
如何做到这一点。
Please watch the youtube video for more clear understanding.
【问题讨论】:
-
“我需要重置操作,但它没有重新安装以前的 preform()”——这是什么意思?你期待什么不会发生?
-
在你的循环中你也有
actions.send_keys(Keys.TAB) actions.reset_actions()- 一方面它看起来不像那个标签被执行过。 -
@C.Peck 它在完成循环时执行 actions.send_keys(Keys.ENTER) actions.perform()
-
是的,这就是代码所说的对吗?我仍然不确定问题是什么
-
@C.Peck 请观看我重新录制并添加到帖子下方的视频