Search code examples
pythonseleniumconfigurationuser-interaction

How can I get data from user for configuring my selenium bot?


I'm working on a Selenium bot using Python.

What I want

When the user runs the python script, a console shows up and asks questions to configure the bot, like:

How many posts do you want? (1-10)
How many users do you want? (1-10)
etc.

After receiving all the answers from the user, it will say something like:

A'ight, we're go for the process!

and does its job.

Question

How can I do something like this, any ideas?

Thanks for your help.


Solution

  • If you start cody in console then you could use standard input() and `print().

    answer1 = input("How many posts do you want? (1-10)")
    answer2 = input("How many users do you want? (1-10)")
    
    print("A'ight, we're go for the process!")
    

    If you don't start in console then you may have to build GUI with tkinter, PyQt, etc. All of them should have dialog boxes to ask one thing. And then you have to use it many times for many questions.

    Based on examples from 15.8. Tkinter Standard Dialog Boxes

    import tkinter as tk
    from tkinter import simpledialog
    from tkinter import messagebox
    
    main_window = tk.Tk()
    main_window.root.withdraw()  # hide main window
    
    answer1 = simpledialog.askinteger("Input", "How many posts do you want? (1-10)",
                                      parent=main_window, minvalue=1, maxvalue=10)
    
    answer2 = simpledialog.askinteger("Input", "How many users do you want? (1-10)",
                                      parent=main_window, minvalue=1, maxvalue=10)
    
    messagebox.showinfo("Info", "A'ight, we're go for the process!")
    
    main_window.destroy()