def open_driver(driver=None):
if driver == None:
driver = webdriver.Chrome(service = ChromeService(executable_path=ChromeDriverManager().install()))
# Enter the search word
driver.get("https://www.google.com/search?q=facebook")
# Open the link
driver.find_element(by=By.XPATH, value='/html/body/div[7]/div/div[10]/div[1]/div[1]/div[3]/div/div/div/div/div/div[1]/a/div[1]/span').click()
# Already_have_an_account choice
driver.find_element(by=By.XPATH, value='/html/body/div[1]/div[1]/div[1]/div[2]/div/div[2]/div/div/div[1]/form/div[1]/div[12]/a').click()
# Click on the email box
driver.find_element(by=By.XPATH, value='/html/body/div[1]/div[1]/div[1]/div/div[2]/div[2]/form/div/div[1]/input').click()
# Enter the email
driver.send_keys(gmail)
# Close the driver
driver.close()
I want to create a facebook bot and I want it to enter the gmail in the box, so I used the send keys to write it and when I run the code, the AttributeError: 'WebDriver' object has no attribute 'send_keys' occurs. Note: I've wroted the gmail in the code but I don't want you to see it for my secure
CodePudding user response:
You need to call send_keys
method of WebElement
, not WebDriver
, so
input_field = driver.find_element(by=By.XPATH, value='/html/body/div[1]/div[1]/div[1]/div/div[2]/div[2]/form/div/div[1]/input')
# Click on the email box
input_field.click()
# Enter the email
input_field.send_keys(gmail)