DEV Community

Cover image for Solving the "Wordle" Game using Python and Selenium

Solving the "Wordle" Game using Python and Selenium

Michael Mintz on January 20, 2022

If you're looking for a complete Python Selenium solution for solving the Wordle Game programmatically, here's one that uses the SeleniumBase frame...
Collapse
 
ifuchs profile image
ifuchs

I have a question which is less about your script than it is about using pytest. I ran pytest -s wordle.py and it runs fine and prints the result to the console. However, I wanted to run the script while logged in via an ssh session and in that case Chrome opens on the Mac screen but does not then run the script. Is there a way to run this "remotely"?

Collapse
 
mintzworld profile image
Michael Mintz

For running Selenium tests remotely, there is something called a "Selenium Grid". Some info on that here: github.com/seleniumbase/SeleniumBa...

Collapse
 
ifuchs profile image
ifuchs • Edited

Selenium Grid is the right way to do remote execution but I found a less attractive way which is to start a terminal session with the screen command and detach the console. If I then ssh in and reattach the console, I am able to run the pytest and get the print output back.

Collapse
 
ifuchs profile image
ifuchs

I meant to say that my question is probably more about selenium and how to run this script remotely.

Collapse
 
ifuchs profile image
ifuchs

New problem. I have this working perfectly on an iMac (with Chrome) but after installing seleniumbase and pytest on my MBP (which is running the same MacOS and Version of Chrome), I am getting this error:

       raise exception(message)
E       selenium.common.exceptions.ElementNotVisibleException: Message:
E        Shadow DOM Element {game-app::shadow game-keyboard::shadow button[data-key="?"]} was not visible after 6 seconds!

/anaconda3/lib/python3.7/site-packages/seleniumbase/fixtures/page_actions.py:163: ElementNotVisibleException

Any idea of what is causing this?

Thread Thread
 
mintzworld profile image
Michael Mintz

The New York Times just acquired Wordle, and there were some strange things happening during the transition for a short time. If there are any issues remaining, I'll be posting an updated script soon.