Hack Forums
[Java] Shitty typing test bot - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Shitty typing test bot (/showthread.php?tid=5582962)



Shitty typing test bot - Ensky - Mar 24, 2017

I'm new to Java, I made a Python version so I thought I'd give it a go in Java too.


Here's it in action (it's slightly slower than the Python version, however.)

[Image: 788dec1e309a896fafe9d6b648903b45.gif]


The code, please criticise me.

PHP Code

<?php 
package typingTest
;

import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class 
TypingBot {
    
    static final 
String URL = "http://typing-speed-test.aoeu.eu/";
    static final 
ChromeDriver DRIVER = new ChromeDriver();
    static List<
WebElement> wordList;
    
    public static 
void main(String[] args) {
        
DRIVER.get(URL);
        
setWordList();
        
run();
    }
    
    
synchronized public static void setWordList() {
        
wordList = DRIVER.findElementsByXPath("//*[@id=\"words\"]/span");
    }
    
    
synchronized public static void run() {
        
WebElement input = DRIVER.findElementById("input");
        for(
WebElement el : wordList) {
            
String word = el.getAttribute("innerHTML") + " ";
            
input.sendKeys(word);
        }
    } 



* - Ensky - Mar 24, 2017

(Mar 24, 2017 06:14 AM)Orka Wrote:  If you want more of a challenge, recreate the test in Java :)

Good idea :) Will look into it thanks