from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
def fill_google_form(form_url, chrome_profile_path):
# Initialize Chrome WebDriver with ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
# Set Chrome options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=" + chrome_profile_path)
# Open the form URL
driver.get(form_url)
# Wait for the page to load
time.sleep(2)
# Find and fill the name field
name_field = driver.find_element_by_xpath("//input[@aria-label='Name']")
name_field.send_keys("asd")
# Find and fill the price field
price_field = driver.find_element_by_xpath("//input[@aria-label='Price']")
price_field.send_keys("123")
# Submit the form
submit_button = driver.find_element_by_xpath("//span[text()='Submit']")
submit_button.click()
# Close the WebDriver
driver.quit()
# Example Google Form URL
form_url = "YOUR_FORM_URL_HERE"
# Path to the Chrome profile directory
chrome_profile_path = "C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3"
# Fill the Google Form using the specified Chrome profile
fill_google_form(form_url, chrome_profile_path)
ERROR
xception has occurred: AttributeError
'str' object has no attribute 'capabilities'
AttributeError: 'str' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
File "C:\Users\user\Desktop\pathway\vask.py", line 7, in fill_google_form
driver = webdriver.Chrome(ChromeDriverManager().install())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\Desktop\pathway\vask.py", line 41, in <module>
fill_google_form(form_url, chrome_profile_path)
AttributeError: 'str' object has no attribute 'capabilities'
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.