import time
n = 0
while True:
try:
driver.found_element_by_xpath ("//*[contains(text(), 'green light')]")
n = 1+ n
print(n)
time(10)
except:
continue
Hello, I'm fiddling with Python at Selenium I'm posting a question because there's a traffic jam.
The function I want to create is a web page with a 'green light' periodically for 5 seconds. At this time, I would like to record the number of times 'green light' appeared on the web page. Actually, I'm only making code by searching, so I don't know if I should write while and try.
Once I run the code I made, n increases by 1 every 10 seconds even if I don't get the green light. So if you delete time (10), n increases very quickly during the five seconds when "green light" comes out, and n increases by one every second when there is no green light.
I'm a total stranger, so I don't know no matter how much I search, so I desperately need the help of masters. Help me
python selenium loops
Let's examine the identity of what needs to be sought more closely. What exactly is the number of green lights? That's actually going to be the number of times the green light has been turned on during a given time interval. It was off until now, but now it means you have to count the number of times it's turned on.
import time
n = 0
turned_on = False # Is the green light on? No.
while True:
try:
driver.found_element_by_xpath ("//*[contains(text(), 'green light')]")
if (turned_on == False): # Wait a minute The green light was off until now, right? All right.
n = n + 1 # Then let's raise the number of green lights
turned_on = True # Okay, the light is on now Remember it well I'll ask you later
EXCEPT: # The green light is off right now
Turned_on = False # Then remember that it's turned off
continue
It'll probably work. Give it a try it!
whileTrue: #Repeat that phrase indefinitely.
try :
If you run the #try syntax and an error occurs, do not print the error out
Run the #except syntax.
except:
© 2024 OneMinuteCode. All rights reserved.