'Python - Use variables from a module in another module while running them in a third "main" module
I have tried for two days to get this to work by trying various things, but I think that I am missing something. It is probably quite trivial, but I can't wrap my head around it.
What I would like to do is a very modular web-automation programme (which uses selenium) where a main script calls several small modules depending on what the user needs. These modules have to be of two types, one for entering data and one for using this data in automation in order to fill boxes in a website. Now, my main problem is that I need the user to be able to type in all the input data first (by using several different modules) and then call all the other modules which will take that data and put in online accordingly.
I have tried global variables, importing one module into the other, making the "input" module as a class instead, etc. I think that I am missing something crucial and I can't quite figure out what it is.
Any help will be greatly appreciated. Cheers!
Example:
a.py
def main():
user = input('insert username: ')
psw = input('insert password: ')
if __name__ == '__main__':
main()
b.py
def main():
driver.find_element_by_id('foo').send_keys(user)
driver.find_element_by_id('faa').send_keys(psw)
if __name__ == '__main__':
main()
c.py
def main():
name = input('insert name: ')
surname = input('insert surname: ')
if __name__ == '__main__':
main()
d.py
def main():
driver.find_element_by_id('fii').send_keys(name)
driver.find_element_by_id('fee').send_keys(surname)
if __name__ == '__main__':
main()
main.py
import a
import b
import c
import d
a.main()
c.main()
b.main()
d.main()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
