Dynamic Variable in Python While LoopCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?How to get the current time in PythonUsing global variables in a functionAccessing the index in 'for' loops?Iterating over dictionaries using 'for' loopsDoes Python have a string 'contains' substring method?

How to minimise the cost of guessing a number in a high/low guess game?

Is it a bad idea to replace pull-up resistors with hard pull-ups?

What are the implications of the new alleged key recovery attack preprint on SIMON?

Plastic-on-plastic lubricant that wont leave a residue?

Who was this character from the Tomb of Annihilation adventure before they became a monster?

What food production methods would allow a metropolis like New York to become self sufficient

Usefulness of complex chord names?

Two researchers want to work on the same extension to my paper. Who to help?

Reaction of borax with NaOH

Ex-manager wants to stay in touch, I don't want to

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

Smallest Guaranteed hash collision cycle length

Should these notes be played as a chord or one after another?

Does kinetic energy warp spacetime?

How are one-time password generators like Google Authenticator different from having two passwords?

Python Pandas Expand a Column of List of Lists to Two New Column

What does a comma mean inside an 'if' statement?

Size of a folder with du

Why does getw return -1 when trying to read a character?

Early arrival in Australia, early hotel check in not available

Bishop Berkeley's ideas put to the test

How to compact two the parabol commands in the following example?

What happens if a creature that would fight isn't on the battlefield anymore?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?



Dynamic Variable in Python While Loop


Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?How to get the current time in PythonUsing global variables in a functionAccessing the index in 'for' loops?Iterating over dictionaries using 'for' loopsDoes Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I got this python selenium while loop code.



  1. If actual points less than or equal to 9 then do Tasks A

  2. Else if actual points greater than 9 do Task B

  3. 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?










share|improve this question
























  • Can you share strpoints value example

    – Sers
    Mar 23 at 12:19











  • Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

    – tehhowch
    Mar 23 at 12:32











  • Updated the answer with example of strpoints

    – Ben Daggers
    Mar 23 at 12:38

















1















I got this python selenium while loop code.



  1. If actual points less than or equal to 9 then do Tasks A

  2. Else if actual points greater than 9 do Task B

  3. 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?










share|improve this question
























  • Can you share strpoints value example

    – Sers
    Mar 23 at 12:19











  • Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

    – tehhowch
    Mar 23 at 12:32











  • Updated the answer with example of strpoints

    – Ben Daggers
    Mar 23 at 12:38













1












1








1


1






I got this python selenium while loop code.



  1. If actual points less than or equal to 9 then do Tasks A

  2. Else if actual points greater than 9 do Task B

  3. 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?










share|improve this question
















I got this python selenium while loop code.



  1. If actual points less than or equal to 9 then do Tasks A

  2. Else if actual points greater than 9 do Task B

  3. 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?







python selenium






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 12:35







Ben Daggers

















asked Mar 23 at 12:03









Ben DaggersBen Daggers

29911038




29911038












  • Can you share strpoints value example

    – Sers
    Mar 23 at 12:19











  • Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

    – tehhowch
    Mar 23 at 12:32











  • Updated the answer with example of strpoints

    – Ben Daggers
    Mar 23 at 12:38

















  • Can you share strpoints value example

    – Sers
    Mar 23 at 12:19











  • Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

    – tehhowch
    Mar 23 at 12:32











  • Updated the answer with example of strpoints

    – Ben Daggers
    Mar 23 at 12:38
















Can you share strpoints value example

– Sers
Mar 23 at 12:19





Can you share strpoints value example

– Sers
Mar 23 at 12:19













Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

– tehhowch
Mar 23 at 12:32





Should the starting code here also be in the while loop e.g. while True:? Otherwise you never execute code that has a chance to modify actualpoints.

– tehhowch
Mar 23 at 12:32













Updated the answer with example of strpoints

– Ben Daggers
Mar 23 at 12:38





Updated the answer with example of strpoints

– Ben Daggers
Mar 23 at 12:38












2 Answers
2






active

oldest

votes


















1














I'm not sure if this will solve the problem, but maybe you can add an actualpoints validation method and variable to hold the last actualpoints value?



Here's your code and some of the additions I made. I reworked your initial process into the while loop if I'm reading TASK A correctly, but feel free to modify this to suit your needs.



strpoints = driver.find_element_by_class_name("fs18").text
points = slice(13, len(strpoints)-20)
actualpoints = strpoints[points]

"""
Create a temporary variable equal to the initial actualpoints value
"""
old_actualpoints = actualpoints

d = 0

def validate_actualpoints():
"""
Simple value check query. Returns actual actualpoints value.
"""
if old_actualpoints != actualpoints:
old_actualpoints = actualpoints

return actualpoints


while old_actualpoints == actualpoints:
while (d + actualpoints < 9):
# TASK A!!!
print(actualpoints + ' Points! Skipping.')
time.sleep(2)
driver.find_element_by_class_name('skip_button_single').click()

""" Move the initial process into the while loop and re-run based on TASK A """
strpoints = driver.find_element_by_class_name("fs18").text
points = slice(13, len(strpoints)-20)
actualpoints = strpoints[points]

time.sleep(8)

if (d >= 10):
break

"""
Update our temporary variable here?
(Possibly not needed.)
"""
old_actualpoints = validate_actualpoints()
break
# TASK B!!!
print(actualpoints + ' Points! Go for it!')





share|improve this answer






























    1














    In code below, time.sleep replaced with wait and while with for loop. Each iteration getting strpoints to use updated value. Regular expression used to extract points number from strpoints.



    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import re

    #...

    wait = WebDriverWait(driver, 10)

    for i in range(10):
    str_points = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "fs18"))).text
    print("str_points: " + str_points)
    points = re.search("\d+", str_points)[0]

    if int(points) > 9:
    break

    wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "skip_button_single"))).click()
    //time.sleep(8)

    print(f'points Points! Go for it!')





    share|improve this answer

























    • i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

      – Ben Daggers
      Mar 23 at 13:18












    • @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

      – Sers
      Mar 23 at 13:20











    • It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

      – Ben Daggers
      Mar 23 at 13:26












    • another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

      – Ben Daggers
      Mar 23 at 13:28











    • @BenDaggers try updated code and share print results

      – Sers
      Mar 23 at 13:33











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313537%2fdynamic-variable-in-python-while-loop%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I'm not sure if this will solve the problem, but maybe you can add an actualpoints validation method and variable to hold the last actualpoints value?



    Here's your code and some of the additions I made. I reworked your initial process into the while loop if I'm reading TASK A correctly, but feel free to modify this to suit your needs.



    strpoints = driver.find_element_by_class_name("fs18").text
    points = slice(13, len(strpoints)-20)
    actualpoints = strpoints[points]

    """
    Create a temporary variable equal to the initial actualpoints value
    """
    old_actualpoints = actualpoints

    d = 0

    def validate_actualpoints():
    """
    Simple value check query. Returns actual actualpoints value.
    """
    if old_actualpoints != actualpoints:
    old_actualpoints = actualpoints

    return actualpoints


    while old_actualpoints == actualpoints:
    while (d + actualpoints < 9):
    # TASK A!!!
    print(actualpoints + ' Points! Skipping.')
    time.sleep(2)
    driver.find_element_by_class_name('skip_button_single').click()

    """ Move the initial process into the while loop and re-run based on TASK A """
    strpoints = driver.find_element_by_class_name("fs18").text
    points = slice(13, len(strpoints)-20)
    actualpoints = strpoints[points]

    time.sleep(8)

    if (d >= 10):
    break

    """
    Update our temporary variable here?
    (Possibly not needed.)
    """
    old_actualpoints = validate_actualpoints()
    break
    # TASK B!!!
    print(actualpoints + ' Points! Go for it!')





    share|improve this answer



























      1














      I'm not sure if this will solve the problem, but maybe you can add an actualpoints validation method and variable to hold the last actualpoints value?



      Here's your code and some of the additions I made. I reworked your initial process into the while loop if I'm reading TASK A correctly, but feel free to modify this to suit your needs.



      strpoints = driver.find_element_by_class_name("fs18").text
      points = slice(13, len(strpoints)-20)
      actualpoints = strpoints[points]

      """
      Create a temporary variable equal to the initial actualpoints value
      """
      old_actualpoints = actualpoints

      d = 0

      def validate_actualpoints():
      """
      Simple value check query. Returns actual actualpoints value.
      """
      if old_actualpoints != actualpoints:
      old_actualpoints = actualpoints

      return actualpoints


      while old_actualpoints == actualpoints:
      while (d + actualpoints < 9):
      # TASK A!!!
      print(actualpoints + ' Points! Skipping.')
      time.sleep(2)
      driver.find_element_by_class_name('skip_button_single').click()

      """ Move the initial process into the while loop and re-run based on TASK A """
      strpoints = driver.find_element_by_class_name("fs18").text
      points = slice(13, len(strpoints)-20)
      actualpoints = strpoints[points]

      time.sleep(8)

      if (d >= 10):
      break

      """
      Update our temporary variable here?
      (Possibly not needed.)
      """
      old_actualpoints = validate_actualpoints()
      break
      # TASK B!!!
      print(actualpoints + ' Points! Go for it!')





      share|improve this answer

























        1












        1








        1







        I'm not sure if this will solve the problem, but maybe you can add an actualpoints validation method and variable to hold the last actualpoints value?



        Here's your code and some of the additions I made. I reworked your initial process into the while loop if I'm reading TASK A correctly, but feel free to modify this to suit your needs.



        strpoints = driver.find_element_by_class_name("fs18").text
        points = slice(13, len(strpoints)-20)
        actualpoints = strpoints[points]

        """
        Create a temporary variable equal to the initial actualpoints value
        """
        old_actualpoints = actualpoints

        d = 0

        def validate_actualpoints():
        """
        Simple value check query. Returns actual actualpoints value.
        """
        if old_actualpoints != actualpoints:
        old_actualpoints = actualpoints

        return actualpoints


        while old_actualpoints == actualpoints:
        while (d + actualpoints < 9):
        # TASK A!!!
        print(actualpoints + ' Points! Skipping.')
        time.sleep(2)
        driver.find_element_by_class_name('skip_button_single').click()

        """ Move the initial process into the while loop and re-run based on TASK A """
        strpoints = driver.find_element_by_class_name("fs18").text
        points = slice(13, len(strpoints)-20)
        actualpoints = strpoints[points]

        time.sleep(8)

        if (d >= 10):
        break

        """
        Update our temporary variable here?
        (Possibly not needed.)
        """
        old_actualpoints = validate_actualpoints()
        break
        # TASK B!!!
        print(actualpoints + ' Points! Go for it!')





        share|improve this answer













        I'm not sure if this will solve the problem, but maybe you can add an actualpoints validation method and variable to hold the last actualpoints value?



        Here's your code and some of the additions I made. I reworked your initial process into the while loop if I'm reading TASK A correctly, but feel free to modify this to suit your needs.



        strpoints = driver.find_element_by_class_name("fs18").text
        points = slice(13, len(strpoints)-20)
        actualpoints = strpoints[points]

        """
        Create a temporary variable equal to the initial actualpoints value
        """
        old_actualpoints = actualpoints

        d = 0

        def validate_actualpoints():
        """
        Simple value check query. Returns actual actualpoints value.
        """
        if old_actualpoints != actualpoints:
        old_actualpoints = actualpoints

        return actualpoints


        while old_actualpoints == actualpoints:
        while (d + actualpoints < 9):
        # TASK A!!!
        print(actualpoints + ' Points! Skipping.')
        time.sleep(2)
        driver.find_element_by_class_name('skip_button_single').click()

        """ Move the initial process into the while loop and re-run based on TASK A """
        strpoints = driver.find_element_by_class_name("fs18").text
        points = slice(13, len(strpoints)-20)
        actualpoints = strpoints[points]

        time.sleep(8)

        if (d >= 10):
        break

        """
        Update our temporary variable here?
        (Possibly not needed.)
        """
        old_actualpoints = validate_actualpoints()
        break
        # TASK B!!!
        print(actualpoints + ' Points! Go for it!')






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 12:59









        Mark MorettoMark Moretto

        47438




        47438























            1














            In code below, time.sleep replaced with wait and while with for loop. Each iteration getting strpoints to use updated value. Regular expression used to extract points number from strpoints.



            from selenium.webdriver.common.by import By
            from selenium.webdriver.support.ui import WebDriverWait
            from selenium.webdriver.support import expected_conditions as EC
            import re

            #...

            wait = WebDriverWait(driver, 10)

            for i in range(10):
            str_points = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "fs18"))).text
            print("str_points: " + str_points)
            points = re.search("\d+", str_points)[0]

            if int(points) > 9:
            break

            wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "skip_button_single"))).click()
            //time.sleep(8)

            print(f'points Points! Go for it!')





            share|improve this answer

























            • i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

              – Ben Daggers
              Mar 23 at 13:18












            • @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

              – Sers
              Mar 23 at 13:20











            • It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

              – Ben Daggers
              Mar 23 at 13:26












            • another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

              – Ben Daggers
              Mar 23 at 13:28











            • @BenDaggers try updated code and share print results

              – Sers
              Mar 23 at 13:33















            1














            In code below, time.sleep replaced with wait and while with for loop. Each iteration getting strpoints to use updated value. Regular expression used to extract points number from strpoints.



            from selenium.webdriver.common.by import By
            from selenium.webdriver.support.ui import WebDriverWait
            from selenium.webdriver.support import expected_conditions as EC
            import re

            #...

            wait = WebDriverWait(driver, 10)

            for i in range(10):
            str_points = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "fs18"))).text
            print("str_points: " + str_points)
            points = re.search("\d+", str_points)[0]

            if int(points) > 9:
            break

            wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "skip_button_single"))).click()
            //time.sleep(8)

            print(f'points Points! Go for it!')





            share|improve this answer

























            • i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

              – Ben Daggers
              Mar 23 at 13:18












            • @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

              – Sers
              Mar 23 at 13:20











            • It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

              – Ben Daggers
              Mar 23 at 13:26












            • another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

              – Ben Daggers
              Mar 23 at 13:28











            • @BenDaggers try updated code and share print results

              – Sers
              Mar 23 at 13:33













            1












            1








            1







            In code below, time.sleep replaced with wait and while with for loop. Each iteration getting strpoints to use updated value. Regular expression used to extract points number from strpoints.



            from selenium.webdriver.common.by import By
            from selenium.webdriver.support.ui import WebDriverWait
            from selenium.webdriver.support import expected_conditions as EC
            import re

            #...

            wait = WebDriverWait(driver, 10)

            for i in range(10):
            str_points = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "fs18"))).text
            print("str_points: " + str_points)
            points = re.search("\d+", str_points)[0]

            if int(points) > 9:
            break

            wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "skip_button_single"))).click()
            //time.sleep(8)

            print(f'points Points! Go for it!')





            share|improve this answer















            In code below, time.sleep replaced with wait and while with for loop. Each iteration getting strpoints to use updated value. Regular expression used to extract points number from strpoints.



            from selenium.webdriver.common.by import By
            from selenium.webdriver.support.ui import WebDriverWait
            from selenium.webdriver.support import expected_conditions as EC
            import re

            #...

            wait = WebDriverWait(driver, 10)

            for i in range(10):
            str_points = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "fs18"))).text
            print("str_points: " + str_points)
            points = re.search("\d+", str_points)[0]

            if int(points) > 9:
            break

            wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "skip_button_single"))).click()
            //time.sleep(8)

            print(f'points Points! Go for it!')






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 23 at 14:03

























            answered Mar 23 at 12:35









            SersSers

            3,3202220




            3,3202220












            • i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

              – Ben Daggers
              Mar 23 at 13:18












            • @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

              – Sers
              Mar 23 at 13:20











            • It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

              – Ben Daggers
              Mar 23 at 13:26












            • another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

              – Ben Daggers
              Mar 23 at 13:28











            • @BenDaggers try updated code and share print results

              – Sers
              Mar 23 at 13:33

















            • i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

              – Ben Daggers
              Mar 23 at 13:18












            • @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

              – Sers
              Mar 23 at 13:20











            • It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

              – Ben Daggers
              Mar 23 at 13:26












            • another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

              – Ben Daggers
              Mar 23 at 13:28











            • @BenDaggers try updated code and share print results

              – Sers
              Mar 23 at 13:33
















            i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

            – Ben Daggers
            Mar 23 at 13:18






            i got this error: TypeError: string indices must be integers. I tried this: actualpoints = int(strpoints[points]) but still the same error.

            – Ben Daggers
            Mar 23 at 13:18














            @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

            – Sers
            Mar 23 at 13:20





            @BenDaggers use points = int(re.search("\d+", strpoints)[0]). check answer update.

            – Sers
            Mar 23 at 13:20













            It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

            – Ben Daggers
            Mar 23 at 13:26






            It (sort of) worked but the variable points is not correct. the actual point i tested was 14 but it only captured 4. I think there's an issue if the actual point is 2 digits. I have updated question showing an example of the strpoints variable.

            – Ben Daggers
            Mar 23 at 13:26














            another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

            – Ben Daggers
            Mar 23 at 13:28





            another issue/error, if the actual point is 1 digit (ex. 5), it returns an error of ValueError: invalid literal for int() with base 10: 'i'

            – Ben Daggers
            Mar 23 at 13:28













            @BenDaggers try updated code and share print results

            – Sers
            Mar 23 at 13:33





            @BenDaggers try updated code and share print results

            – Sers
            Mar 23 at 13:33

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313537%2fdynamic-variable-in-python-while-loop%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현