1
from selenium import webdriver
import webbrowser
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
import smtplib
import sys


option = webdriver.ChromeOptions()
option.add_argument("--start-maximized")
chrome_path = "C:\Program Files\Google\Chrome\Application\chrome.exe"

driver = webdriver.Chrome(chrome_path, options=option)

driver.get('https://play.typeracer.com/')

while True:
    try:
        driver.find_element_by_xpath("""//*[@id="dUI"]/table/tbody/tr[2]/td[2]/div/div[1]/div/table/tbody/tr[3]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/a""").click()
        break
    except:
        continue
sleep(5)

try:
    words = driver.find_element_by_xpath("""//*[@id="gwt-uid-15"]/table/tbody/tr[2]/td/table/tbody/tr[1]/td/table/tbody/tr[1]/td/div/div/span[1]""").text
except:
    print("")

try:
    words += driver.find_element_by_xpath("""//*[@id="gwt-uid-15"]/table/tbody/tr[2]/td/table/tbody/tr[1]/td/table/tbody/tr[1]/td/div/div/span[2]""").text + " "
except:
    print("")

try:
    words += driver.find_element_by_xpath("""//*[@id="gwt-uid-15"]/table/tbody/tr[2]/td/table/tbody/tr[1]/td/table/tbody/tr[1]/td/div/div/span[3]""").text
except:
    print("")


print(words)


inputField = driver.find_element_by_xpath("""//*[@id="gwt-uid-15"]/table/tbody/tr[2]/td/table/tbody/tr[2]/td/input""")

#Sleeps because the game can detect cheaters if the sleep is not used...Slows down the WPM slightly
for character in words:
    inputField.send_keys(character)
    sleep(0.1)

I cannot get the driver.get() to work. I know the chrome path is correct since it does open a new chrome window and it does not open a webpage. Can you fix my code without changing the option's variable. I just put the error up right now by doing a traceback call.

Error is:

  File "C:\Users\vidit\Documents\CODE\typeracer.py", line 14, in <module>
    driver = webdriver.Chrome(chrome_path, options=option)
  File "C:\Users\vidit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\vidit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self.assert_process_still_running()
  File "C:\Users\vidit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 109, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0

My chrome instance did not close or anything just to clarify that. Chrome was still running it did not crash or close.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Update the question with the error stack trace. – undetected Selenium Nov 24 '20 at 13:22
  • It seems to be on the `driver = webdriver.Chrome(chrome_path, options=option)` line. Did you download the driver from https://sites.google.com/a/chromium.org/chromedriver/ and make sure it is the correct version that matches your Chrome version? – formicaman Nov 24 '20 at 14:53
  • Yes i agree with formicaman you should download that matches with your current chrome version and give `chrome_path = "your chromedriver path here"` – Zac Nov 24 '20 at 16:29

1 Answers1

0

The constructor is:

driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=option)

Where the first argument Key is executable_path which points to the absolute path of the ChromeDriver binary but not of chrome.exe.

So you need to change the value of chrome_path with chromedriver_path downloading it from ChromeDriver - WebDriver for Chrome and your effective code block will be:

option = webdriver.ChromeOptions()
option.add_argument("--start-maximized")
chromedriver_path = r'C:\path\to\chromedriver.exe'

driver = webdriver.Chrome(executable_path=chromedriver_path, options=option)
driver.get('https://play.typeracer.com/')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352