I'm trying to use Selenium to automate creating Google Documents and adding random text to them. I've created a list called doccontent in the program that it pulls from to enter into the body of the Google docs but I can't seem to get it to work. Here is part of my code:
import random
from selenium import webdriver
import time
driver = webdriver.Chrome()
#creating doc
driver.get("https://docs.google.com/document/u/0/")
time.sleep(random.randint(1,2))
newdoc = driver.find_element_by_xpath('//*[@id=":1d"]/div[1]')
newdoc.click()
time.sleep(2)
#adding random doc name
rename = driver.find_element_by_class_name('docs-title-input')
rename.click()
docname = "test" + str(random.randint(1,600))
rename.send_keys(docname)
body = driver.find_element_by_class_name('kix-lineview')
time.sleep(1)
docwords = random.choice(doccontent)
body.send_keys(docwords)
It comes back with the error:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element (Session info: chrome=69.0.3497.100) (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.17134 x86_64)
Edit:
Just changed it to:
#creating doc
driver.get("https://docs.google.com/document/u/0/")
time.sleep(random.randint(1,2))
newdoc = driver.find_element_by_xpath('//*[@id=":1d"]/div[1]')
newdoc.click()
time.sleep(2)
#adding random doc name
rename = driver.find_element_by_class_name('docs-title-input')
rename.click()
docname = "test" + str(random.randint(1,600))
rename.send_keys(docname)
body = driver.find_element_by_class_name('kix-page-column')
time.sleep(1)
docwords = random.choice(doccontent)
actions = ActionChains(driver)
actions.send_keys(Keys.TAB * 15)
actions.perform()
time.sleep(1)
body.send_keys(docwords)
This is to try and tab into the document, but it still gives an error:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element (Session info: chrome=69.0.3497.100) (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.17134 x86_64)