0

I made a post earlier about making the bot, and it works, thanks to Justin Ezequiel, but it stops randomly. Any fixes?

Python:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time

x = 1

driver = webdriver.Chrome()
driver.get('https://hackertyper.net/')
while x == 1:
    actions = ActionChains(driver)
    actions.send_keys("I'm trying to make a bot to see how far I can get in hackertyper")
    actions.perform()
    time.sleep(0.1)
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

1 Answers1

0

To send a character sequence within Hacker Typer you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH:

    driver.get('https://hackertyper.net/')
    x = 1
    while x == 1:
        ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='main']//pre//span[@id='cursor']")))).send_keys("I'm trying to make a bot to see how far I can get in hackertyper").perform()
        time.sleep(0.5)
    
  • Using CSS_SELECTOR:

    driver.get('https://hackertyper.net/')
    x = 1
    while x == 1:
        ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#main pre span#cursor")))).send_keys("I'm trying to make a bot to see how far I can get in hackertyper").perform()
        time.sleep(0.5)
    
  • Note: You have to add the following imports :

    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

hackertyper.png

DebanjanB
  • 118,661
  • 30
  • 168
  • 217