Uncategorized

Code for Python Selenium – automatically filling out a form

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
#REQUIRED FOR HEADLESS PART 1
from selenium.webdriver.chrome.options import Options
#REQUIRED FOR HEADLESS
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys

#Set location of Chrome Driver
s = Service('/usr/local/bin/chromedriver')

#Set some selenium chrome options
chromeOptions = Options()
chromeOptions.headless = False
driver = webdriver.Chrome(service=s, options=chromeOptions)

list_data = []

def initialize_browser():
    driver.get("InsertYOURURL")
    print("starting_Driver")
    time.sleep(1)
    Select_Box_Name = driver.find_element(by=By.NAME, value="your-name")
    Select_Box_Name.click()
    time.sleep(1)
    Select_Box_Name.send_keys('This Is My Name')
    Select_Box_Name = driver.find_element(by=By.NAME, value="your-email")
    Select_Box_Name.click()
    time.sleep(1)
    Select_Box_Name.send_keys('automateWithJonathan@Gmail.com')
    Select_Box_Name = driver.find_element(by=By.NAME, value="your-subject")
    Select_Box_Name.click()
    time.sleep(1)
    Select_Box_Name.send_keys('This Is My Subject')
    Select_Box_Name = driver.find_element(by=By.NAME, value="your-message")
    Select_Box_Name.click()
    time.sleep(1)
    Select_Box_Name.send_keys('This Is My Message')
    click_send = driver.find_element(by=By.CLASS_NAME, value="wpcf7-submit")
    click_send.click()


initialize_browser()

#driver.quit()