Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eviltester/42de6e41d2d1cdd591be0fc024f10920 to your computer and use it in GitHub Desktop.
Save eviltester/42de6e41d2d1cdd591be0fc024f10920 to your computer and use it in GitHub Desktop.
play tic tac toe org random bot
// https://playtictactoe.org/
function playGame(){
var restart = document.querySelector("div.restart");
if(restart.style.display=="block"){
restart.click()
}else{
var squares = document.querySelectorAll("div.square > div:not(.x):not(.o)");
var item=Math.floor(Math.random()*squares.length)
squares[item].parentElement.dispatchEvent(new Event('mousedown'));
}
}
var playBot = window.setInterval(playGame,500);
//window.clearInterval(playBot);
// And my notes that I used during recon when building the code
/*
restart div overlay
div.restart
document.querySelector("div.restart").click()
document.querySelector("div.restart").style.display
div.square
div.square > div:not(.x):not(.o)
document.querySelectorAll("div.square")[0].dispatchEvent(new Event('mousedown'))
document.querySelectorAll("div.square > div:not(.x):not(.o)")[0].parentElement.dispatchEvent(new Event('mousedown'))
true
document.querySelectorAll("div.square > div:not(.x):not(.o)")[0].dispatchEvent(new Event('mousedown', {"bubbles":true}))
*/
@eviltester
Copy link
Author

I was inspired to automate this game based on Angie Jones video using Java and WebDriver to provide another example of automating the same game.

Angie's video:

https://www.youtube.com/watch?v=nZZD2aFAm_A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment