I got this python selenium while loop code.
- If actual points less than or equal to 9 then do Tasks A
- Else if actual points greater than 9 do Task B
- Perform a While Loop until the actual points is greater than 9
Here's my Code
strpoints = driver.find_element_by_class_name("fs18").text
points = slice(13, len(strpoints)-20)
actualpoints = strpoints[points]
d = 0
while (d + actualpoints <9):
# TASK A!!!
print(actualpoints + ' Points! Skipping.')
time.sleep(2)
driver.find_element_by_class_name('skip_button_single').click()
time.sleep(8)
if (d >= 10):
break
# TASK B!!!
print(actualpoints + ' Points! Go for it!')
Issue:
The code above is not working properly because the variable actualpoints is dynamic.
IF actualpoints < 9 it will performed the assigned TASK B BUT UNFORTUNATELY it returns the same variable and it never changes.
Task A, reloads the page and displays a new number that should be stored in a variable called actualpoints.
Other details related to my code and variables:
- strpoints = getting the string that holds the number(s). Part of this string is static text and dynamic (numbers). Example: You will get 12 points for following.
- points = slicing the
strpoints. - actualpoints = the result after slicing the
strpoints. Dynamic value. - will perform a loop until > 10
any idea what's wrong with the code?
strpointsvalue examplewhileloop e.g.while True:? Otherwise you never execute code that has a chance to modifyactualpoints.