Selenium python do test every 10 seconds

2024/11/24 18:53:36

I am using selenium (python) testing and I need to test my application automatically every 10 seconds.

How can I do this?

Answer

You could use threading.Timer:

import threading
import loggingdef print_timer(count):if count:t = threading.Timer(10.0, print_timer,args=[count-1])t.start()logger.info("Begin print_timer".format(c=count))time.sleep(15)logger.info("End print_timer".format(c=count))def using_timer():t = threading.Timer(0.0, print_timer,args=[3])t.start()if __name__=='__main__':logging.basicConfig(level=logging.DEBUG,format='%(threadName)s: %(asctime)s: %(message)s',datefmt='%H:%M:%S')    using_timer()

yields

Thread-1: 06:46:18: Begin print_timer  --| 10 seconds
Thread-2: 06:46:28: Begin print_timer  --
Thread-1: 06:46:33: End print_timer      | 10 seconds
Thread-3: 06:46:38: Begin print_timer  --
Thread-2: 06:46:43: End print_timer      | 10 seconds
Thread-4: 06:46:48: Begin print_timer  --
Thread-3: 06:46:53: End print_timer
Thread-4: 06:47:03: End print_timer

Note that this will spawn a new thread ever 10 seconds. Be sure to provide some way for the thread-spawning to cease before the number of threads becomes intolerable.

https://en.xdnf.cn/q/120503.html

Related Q&A

Type Object has no attribute

I am working on a program, but I am getting the error "Type object Card has no attribute fileName. Ive looked for answers to this, but none that Ive seen is in a similar case to this.class Card: R…

Generate random non repeating samples from an array of numbers

I made a battleships game and I now need to make sure that the computer doesnt attack at the same spot twice.My idea of it is storing each shots co-ordinates in a variable which gets added to whenever …

How to get back fo first element in list after reaching the end? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…

Collision detection on the y-axis does not work (pygame)

I am trying to get the collision detection in my code to work. I am using vectors and I want the player sprite to collide and stop when it collides with a sprite group called walls. The problem is that…

Search for string within files of a directory

I need help writing a light weight Python (v3.6.4) script to search for a single keyword within a directory of files and folders. Currently, I am using Notepad++ to search the directory of files, altho…

Extract parent and child node from python tree

I am using nltks Tree data structure.Below is the sample nltk.Tree.(S(S(ADVP (RB recently))(NP (NN someone))(VP(VBD mentioned)(NP (DT the) (NN word) (NN malaria))(PP (TO to) (NP (PRP me)))))(, ,)(CC an…

Click button with selenium and python

Im trying to do web scraping with python on and Im having trouble clicking buttons. Ive tried 3 different youtube videos using Xpath, driver.find_element_by_link_text, and driver.find_element. What am …

Combinations of DataFrames from list

I have this:dfs_in_list = [df1, df2, df3, df4, df5]I want to concatenate all combinations of them one after the other (in a loop), like:pd.concat([df1, df2], axis=1) pd.concat([df1, df3], axis=1) p…

Python: iterate through dictionary and create list with results

I would like to iterate through a dictionary in Python in the form of:dictionary = {company: {0: apple,1: berry,2: pear},country: {0:GB,1:US,2:US} }To grab for example: every [company, country] if coun…

Jira Python: Syntax error appears when trying to print

from jira.client import jiraoptions = {server: https://URL.com} jira = JIRA(options, basic_auth=(username, password))issues = jira.search_issues(jqlquery) for issue in issues:print issueI want to print…