perform() and reset_actions() in ActionChains not working selenium python

2024/10/9 2:31:34

This is the code that habe no error:

perform() and reset_actions()

but these two functions have to work combinedly

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 = 3sleep_time = 1implicitly_wait_time = 4actions.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")

I am working with navigation() functions:

in the loop area

actions.send_keys(Keys.TAB)

actions.reset_actions()

I need to reset action but it's not reseating previous preform()

What will be the batter way to do that.

Please watch the youtube video for more clear understanding.

Answer

The issue is fixed already but will be in the next releases. Check the issue #6837 in the github.

For now you can use temporary solution.

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 = 4sleep_time = 1implicitly_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()
https://en.xdnf.cn/q/70071.html

Related Q&A

nosetests not recognized on Windows after being installed and added to PATH

Im on exercise 46 of Learn Python the Hard Way, and Im meant to install nose and run nosetests. Ive installed nose already using pip, but when I run nosetests in the directory above the tests folder, I…

Using a context manager with mysql connector python

Im moving my code across from an sqlite database to mysql and Im having a problem with the context manager, getting the following attribute error.Ive tried combinations of mydb.cursor() as cursor, mydb…

Value of Py_None

It is clear to me that None is used to signify the lack of a value. But since everything must have an underlying value during implementation, Im looking to see what value has been used in order to sign…

Getting the href of a tag which is in li

How to get the href of the all the tag that is under the class "Subforum" in the given code?<li class="subforum"> <a href="Link1">Link1 Text</a> </l…

Put value at centre of bins for histogram

I have the following code to plot a histogram. The values in time_new are the hours when something occurred.time_new=[9, 23, 19, 9, 1, 2, 19, 5, 4, 20, 23, 10, 20, 5, 21, 17, 4, 13, 8, 13, 6, 19, 9, 1…

plot in Pandas immediately closes

I have a problem of plotting the data. I run the following python code:import pandas as pd df = pd.read_csv("table.csv")values = df["blah"] values.plot() print 1df[blahblah].plot() …

Django template: Embed css from file

Im working on an email template, therefor I would like to embed a css file<head><style>{{ embed css/TEST.css content here }}</style> </head>instead of linking it<head><…

handling async streaming request in grpc python

I am trying to understand how to handle a grpc api with bidirectional streaming (using the Python API).Say I have the following simple server definition:syntax = "proto3"; package simple;serv…

Add new column to a HuggingFace dataset

In the dataset I have 5000000 rows, I would like to add a column called embeddings to my dataset. dataset = dataset.add_column(embeddings, embeddings) The variable embeddings is a numpy memmap array of…

Django: how to order_by on a related field of a related field

Im using annotate to add a property to an object which I can then use for order_by. However, I want to annotate on a field of a relation on a relation. I know I should be able to get to the field someh…