OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Selenium only opens links twice within a loop

  • Thread starter Thread starter Singh Jaskeat
  • Start date Start date
S

Singh Jaskeat

Guest
I have this program which logs into microsoft admin then creates new user profiles and i have a for loop that does it but it always only runs twice before stopping. Could this be microsoft limmiting sessions or something else?

The add user page is opened and the rest of the code is ran fine for the first two loops but when the loop is ran for the third time, it doesnt open the page. I tried it on different computers and different users and still the same problem.

Sometimes it only runs once, i tried to run the code line by line and i can confirm that the for loop runs fine but when it gets to the driver.get() line inside the for loop it just doesnt open. Is there a server request limit or something like that?

I have hidden most of the code just for convenience of privacy

Code:
def minecraft_creation():
    global minecraft_student_counter

    driver.maximize_window()

    driver.get("https://admin.microsoft.com/")
    sleep(4)

   #i log into the account here (hidden)
  

    for i in range(len(csv)):

                driver.get(
                    "https://admin.microsoft.com/Adminportal/Home#/users/:/adduser"
                )
                sleep(4)

WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH,
                            "//input[@data-automation-id='AddUserWizard_lastName']",
                        )
                    )
                ).send_keys(last_name)
                WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH,
                            "//input[@data-automation-id='AddUserWizard_firstName']",
                        )
                    )
                ).send_keys(first_name)
                sleep(2)
                WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH,
                            "//input[@data-automation-id='AddUserWizard_displayName']",
                        )
                    )
                ).click()
                sleep(2)

                WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH,
                            "//input[@data-automation-id='AddUserWizard_userName']",
                        )
                    )
                ).send_keys(username)
                sleep(2)
                WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH,
                            "//input[@data-automation-id='AddUserWizard_password']",
                        )
                    )
                ).send_keys(str(datetime.today().year))
                # driver.execute_script("arguments[0].click();", driver.find_element(By.CSS_SELECTOR, ".ms-Panel-content .ms-Checkbox.is-checked input"))
                sleep(4)

                WebDriverWait(driver, 20).until(
                    EC.presence_of_element_located(
                        (
                            By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']",
                        )
                    )
                ).click()
                sleep(1)

                driver.execute_script(
                    "arguments[0].click();",
                    driver.find_element(
                        By.XPATH,
                        "//input[@data-automation-id='ProductSkuId_94763226-9b3c-4e75-a931-5c89701abe66']",
                    ),
                )
                sleep(1)

                driver.find_element(
                    By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
                ).click()
                sleep(1)

                driver.find_element(
                    By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
                ).click()
                sleep(3)
                

                driver.find_element(
                    By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
                ).click()
                sleep(3)


                create_list.append(username)

                account_notification = account_notification + username + "\n"
<p>I have this program which logs into microsoft admin then creates new user profiles and i have a for loop that does it but it always only runs twice before stopping. Could this be microsoft limmiting sessions or something else?</p>
<p>The add user page is opened and the rest of the code is ran fine for the first two loops but when the loop is ran for the third time, it doesnt open the page. I tried it on different computers and different users and still the same problem.</p>
<p>Sometimes it only runs once, i tried to run the code line by line and i can confirm that the for loop runs fine but when it gets to the driver.get() line inside the for loop it just doesnt open. Is there a server request limit or something like that?</p>
<p>I have hidden most of the code just for convenience of privacy</p>
<pre class="lang-py prettyprint-override"><code>def minecraft_creation():
global minecraft_student_counter

driver.maximize_window()

driver.get("https://admin.microsoft.com/")
sleep(4)

#i log into the account here (hidden)


for i in range(len(csv)):

driver.get(
"https://admin.microsoft.com/Adminportal/Home#/users/:/adduser"
)
sleep(4)

WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH,
"//input[@data-automation-id='AddUserWizard_lastName']",
)
)
).send_keys(last_name)
WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH,
"//input[@data-automation-id='AddUserWizard_firstName']",
)
)
).send_keys(first_name)
sleep(2)
WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH,
"//input[@data-automation-id='AddUserWizard_displayName']",
)
)
).click()
sleep(2)

WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH,
"//input[@data-automation-id='AddUserWizard_userName']",
)
)
).send_keys(username)
sleep(2)
WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH,
"//input[@data-automation-id='AddUserWizard_password']",
)
)
).send_keys(str(datetime.today().year))
# driver.execute_script("arguments[0].click();", driver.find_element(By.CSS_SELECTOR, ".ms-Panel-content .ms-Checkbox.is-checked input"))
sleep(4)

WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(
By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']",
)
)
).click()
sleep(1)

driver.execute_script(
"arguments[0].click();",
driver.find_element(
By.XPATH,
"//input[@data-automation-id='ProductSkuId_94763226-9b3c-4e75-a931-5c89701abe66']",
),
)
sleep(1)

driver.find_element(
By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
).click()
sleep(1)

driver.find_element(
By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
).click()
sleep(3)


driver.find_element(
By.XPATH, "//button[@data-automation-id='addUserWizardNextBtn']"
).click()
sleep(3)


create_list.append(username)

account_notification = account_notification + username + "\n"
</code></pre>
 
Top