Search code examples
pythonlibraries

How to make pyautogui type a link in google as well as loop over a user-decided amount of times?


Am running this code, but it is not typing the kahoot link, it is only typing chrome. Here's the code:

import pyautogui as gui
import random
gui.FAILSAFE = False
pin = input('What is the kahoot code? ')
name = input('Pick a bot name, no numbers. ')
nums = input('Select the amount of bots. Maximum 100. ')
a = str(list(range(100)))
gui.move(-1000, 1000)
gui.click()
gui.write('Chrome')
gui.press('Enter')
for num in nums:
    x = random.choice(a)
    gui.write('Kahoot.it')
    gui.press('Enter')
    gui.write(pin)
    gui.press('Enter')
    gui.write(name + x)
    gui.press(enter)
    gui.keyDown('ctrl')
    gui.keyDown('t')
    gui.keyUp('ctrl')
    gui.keyUp('t')

Solution

  • Maybe the Chrome navigator isn't loaded when pyautogui starts to write. You should use time.sleep to wait a little bit while Chrome is loading. However, I think you should use the selenium package if you want to use the navigator, as it can manipulate it more precisely than pyautogui.

    Hope it helped you.