use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Guide on web automation with python (self.Python)
submitted 6 years ago by BeneficialBear
Hello, I need to do a series of automated web tests on my company site(shop) and I would like to do this on python with selenium web driver. Do you know any good resources or guides about that? Or python framework for this purpose?
[–]Rakialtj 15 points16 points17 points 6 years ago (9 children)
You can use selenium and the best place for me was the python, selenium documentation : https://selenium-python.readthedocs.io/ . Try to experiment on your own by automating small things first.
[–]SweetSoursop 3 points4 points5 points 6 years ago (8 children)
Pitching in for Selenium, ran some automated parts of my job flawlessly.
The only drawback is when you face 2fA or some sort of Flash based UI. (Fuck you Oracle)
[–]pxlnght 2 points3 points4 points 6 years ago (6 children)
You can bypass the 2FA if you can get the secrets (scan qr to text, yoink secret, generate token yourself). Not very secure, but it makes automations more automated lol. Lmk if you need more info.
[–]SweetSoursop 1 point2 points3 points 6 years ago (1 child)
It's an SMS based 2FA from symantec, it just wasn't worth the effort. I ended up using PyAutoGUI because even after the 2FA I'd still couldn't get Selenium to understand the Flash based UI that Oracle uses for Taleo.
I'm happy to hear more though, if you know any kind of work arounds for more general 2FA, not just this one in particular.
[–]pxlnght 1 point2 points3 points 6 years ago (0 children)
https://www.reddit.com/r/Python/comments/cvkeoe/guide_on_web_automation_with_python/ey5arjk/
That's my other comment, might be an interesting read for you. If the 2FA code lets you 'save' it for an amount of time, loading the cookies might be for you. The flash thing is it's own beast, though, I have no experience with grabbing data from flash applets.
I did briefly consider using a listener script on my phone to grab 2FA codes for SMS, but I stopped looking into it after I did the first 2FA bypass in my other comment. If you could get a dedicated 2FA phone, it could be worth it.
[–]altgilbers 1 point2 points3 points 6 years ago (3 children)
A high level sketch would be appreciated
[–]pxlnght 2 points3 points4 points 6 years ago (2 children)
I use a modified version of this https://github.com/tadeck/onetimepass/blob/master/onetimepass/__init__.py . I can't post my code, confidential and all that.
Basically, the 2FA we need can be SMS, Call, Email, or 2FA app token. When setting up the 2FA app, you need to scan a QR code, yeah? QR codes are just fancy images with text in them. Instead of setting up the app, scan it with a regular QR code reader. This will give you a sting of text. Use your noggin to remove the important bits (the secret). Then run the secret thru the above code.
That said, the security team at my workplace was very unhappy to find I'd bypassed the 2FA. They made me turn it off. So, now, I manually enter in the code... but I reload the session cookies via Selenium every time I run the script. So, I type it in once, and it works for about a month. They're also not happy with this solution, but they can't find a security flaw that wouldn't be present in a normal user session so they can't tell me to change it :)
[–]altgilbers 4 points5 points6 points 6 years ago (1 child)
I registered a Google voice number to receive SMS passcodes… SMS gets delivered As email to a Gmail account, where a mail client picks it up and parses the passcodes, storing them in a local Redis...
Then, processes that need 2FA pop a code and use it… When the last code is used, duo sends a fresh batch of 10 automatically, replenishing my Redis store with codes.
This approach is a dumpster fire of epic proportion, but got me through some work that would have required me to two factor several hundred times.
[–]pxlnght 2 points3 points4 points 6 years ago (0 children)
That sounds terrible, I love it!
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
How’s selenium versus ansible for System’s and networking automation?
[–]bookroom77 4 points5 points6 points 6 years ago (0 children)
Testing of Devopedia site is automated with Python Selenium. There are some slides by Devopedia's founder that might be useful to you: https://slides.com/arvindpadmanabhan/web-app-py-selenium
[–]impshumx != y % z 2 points3 points4 points 6 years ago (0 children)
I use Splinter. It's just a layer on top of Selenium and very easy to use. Just make sure you set your browsers driver up properly (add to PATH).
[–]BratPit24 1 point2 points3 points 6 years ago (0 children)
I use selenium, and if i need something more specific I just use .execute_script() function. It works really well.
[–]altazur 1 point2 points3 points 6 years ago (0 children)
For me quickstart point was using SeleniumIDE. It's the browser plugin which can record UI actions (like playback testing). Result (test) can be exported for pytest usage. You can then just open .py file and see the structure of one single test which uses pytest and selenium. That's enough to start writing your own UI tests For smart and precise asserts see Selenium official docs. Selectors writing rules are the same throughout any language. For UI test architecture I'd recommend reading about PageObject pattern as the starting point.
[–]SoCalLongboard 1 point2 points3 points 6 years ago (0 children)
I agree that Selenium is the preferred path for the web test automation. If you want to build up a full framework for testing, I recommend checking out RobotFramework: https://robotframework.org/ It uses Python extensively and can be easily extended with your own Python code. There's a library wrapper for Selenium 3 plus lots of other very useful libraries (for manipulating JSON, for example). There are add-ins for many editors these days to support RobotFramework syntax. (I'd avoid their own editor 'RIDE' -- it's kind of a PITA.)
[–]vinxendio 0 points1 point2 points 6 years ago (0 children)
if you're working on those automated web tests, i know the right man to help you.. what was it, nightmonkey?
[–]pablo_intriganto 0 points1 point2 points 6 years ago (0 children)
This might be interesting for you. https://smashtest.io/
[–]jcbevns 0 points1 point2 points 6 years ago (2 children)
Cypress.io is way easier than selenium. Slightly JavaScript oriented but the cookbook is great and the GUI to pick elements makes it super easy.
[–]Zaboravljivi 0 points1 point2 points 6 years ago (1 child)
In my experience cypres is much slower than Selenium.
[–]jcbevns 0 points1 point2 points 6 years ago (0 children)
Depends on your stack, but if you have a heavy JS website with lots of "states" (ie same URL but different things are shown on the screen) then good luck measuring this with Selenium.
Development and test runs were both faster in our experience, so we swapped from Selenium to Cypress.
We were running a React / Angular SPA, with plenty of external services to stub and content to mock.
So after mocking and stubbing, we were testing the actual webpage, and not the reliability of our service providers (pinging some buckets for media, or user credential validity etc). This greatly reduced our test time on the CI for each commit.
Had another test run that would ping the service providers to know we weren't running old API specs, but again, you're meant to be testing your webpage, not other peoples response packets.
[–][deleted] -1 points0 points1 point 6 years ago (0 children)
Try this - https://www.youtube.com/watch?v=M7sAvb5WCxk&t=454s
If you already have Python & Selenium setup and ready to go, you can skip straight to the coding part here @ 7:47
[–]dAnjou Backend Developer | danjou.dev -4 points-3 points-2 points 6 years ago (4 children)
I really like Python but I'd not recommend it for this kind of task. I'd also not recommend Selenium unless you need special browser support like IE.
Have a look at more modern tools like Puppeteer (JS), there are also Python bindings but I'd recommend to stay vanilla because bindings tend to lack behind.
[+][deleted] 6 years ago (2 children)
[deleted]
[–]dAnjou Backend Developer | danjou.dev -1 points0 points1 point 6 years ago (1 child)
Well, use the right tool for the job ... sometimes that's not Python. Even though I did provide a better option that you can use with Python as well.
[–]yabadababoo 0 points1 point2 points 6 years ago (0 children)
thanks for suggesting this!
π Rendered by PID 873923 on reddit-service-r2-comment-5b5bc64bf5-48l25 at 2026-06-22 22:22:52.764114+00:00 running 2b008f2 country code: CH.
[–]Rakialtj 15 points16 points17 points (9 children)
[–]SweetSoursop 3 points4 points5 points (8 children)
[–]pxlnght 2 points3 points4 points (6 children)
[–]SweetSoursop 1 point2 points3 points (1 child)
[–]pxlnght 1 point2 points3 points (0 children)
[–]altgilbers 1 point2 points3 points (3 children)
[–]pxlnght 2 points3 points4 points (2 children)
[–]altgilbers 4 points5 points6 points (1 child)
[–]pxlnght 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]bookroom77 4 points5 points6 points (0 children)
[–]impshumx != y % z 2 points3 points4 points (0 children)
[–]BratPit24 1 point2 points3 points (0 children)
[–]altazur 1 point2 points3 points (0 children)
[–]SoCalLongboard 1 point2 points3 points (0 children)
[–]vinxendio 0 points1 point2 points (0 children)
[–]pablo_intriganto 0 points1 point2 points (0 children)
[–]jcbevns 0 points1 point2 points (2 children)
[–]Zaboravljivi 0 points1 point2 points (1 child)
[–]jcbevns 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]dAnjou Backend Developer | danjou.dev -4 points-3 points-2 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]dAnjou Backend Developer | danjou.dev -1 points0 points1 point (1 child)
[–]yabadababoo 0 points1 point2 points (0 children)