I'm trying to login via Python and Selenium, but I can't figure out the issue with the following line: driver = webdriver.Chrome(executable_path= r'C:\Program Files (x86)', options=options)
I keep getting an error in Pycharm, it says that executable path is an unexpected argument. I checked and ensured the driver file was in the right place. Any idea what it could be. I'm trying to log-in to the following website: https://sph.synxis.com/pms-web-ui/login#/logout-success
`from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
# Set the path to the WebDriver executable (e.g., chromedriver for Chrome)
webdriver_path = r'C:\Program Files (x86)\chromedriver.exe'
# Set the login credentials
username = 'xxxxxx'
password = 'xxxxxxxx'
# Configure the WebDriver options
options = webdriver.ChromeOptions()
options.binary_location = 'path/to/chrome.exe'
# Add any additional options or preferences if needed
driver = webdriver.Chrome(executable_path= r'C:\Program Files (x86)', options=options)
# Instantiate the WebDriver
# Navigate to the login page
driver.get('https://sph.synxis.com/pms-web-ui/login#/logout-success')
# Wait for the login page to load
wait = WebDriverWait(driver, 10)
login_form = wait.until(EC.presence_of_element_located((By.ID, 'login-form')))
# Fill in the login form
username_input = driver.find_element(By.ID, 'username')
password_input = driver.find_element(By.ID, 'password')
username_input.send_keys(username)
password_input.send_keys(password)
# Submit the login form
password_input.send_keys(Keys.RETURN)
# Wait for the login to complete and any subsequent page to load
# You can add additional wait conditions here based on your requirements
# Perform further actions or navigate to other pages as needed
# Close the browser
driver.quit()
I have strong evidence that your code is copied from ChatGPT:
While the website might not be 100% accurate, for example, the last three comments were deemed to be from humans when it very clearly was from the AI replying to you.
With the above said, now, let's look at your code.
Are your sure your webdriver executable is actually there? It is a really odd place to store
chromedriver.exe. I highly doubt that is actually the path to the driver executable.You need to verify the path first, open CMD and paste
"C:\Program Files (x86)\chromedriver.exe"and press Enter. If you get the following error:It means the executable isn't there.
If you don't know how to open CMD, Google it, don't ask ChatGPT.
You need to find the correct path to the executable, again, if you don't know how, Google it.
Though you need to actually download
chromedriverfirst, if you haven't downloaded it already, which is very likely. Go to https://chromedriver.chromium.org/downloads to download it, again, Google if necessary.That being said, you need to change the following line:
r'C:\Program Files (x86)'needs to be the actual chromedriver path, usewebdriver_pathhere. For example, mine's path is"D:\CliExec\chromedriver.exe".So if I were to use the above syntax, I would do:
But you don't actually need to explicitly pass the paths as arguments.
seleniumautomatically finds it for you.Just do
webdriver.Chrome(). And if that doesn't work, make surechromedriver.exeis downloaded, find its path, put the folder it is inside in PATH environment variable. Google if necessary, again.The above imported items were never used, and I never knew anyone who used
webdriver_manager, I only confirmed its existence by search PyPI. Delete these lines.Then your url:
You don't actually need
"#/logout-success"part, because that logs you out of your account, but you are trying to login to your account, and when you start a driver session, it is automatically logged out anyway, the last part is only garbage and wastes your time by trying to log out.I have visited that webpage, and I can confirm there are absolutely no elements that have these generic ids
'username', 'password', 'login-form'.Web scraping 101, if you don't know about how to find an element, press Ctrl + Shift + C and then left click on the element. The element will then be highlighted in the "Inspector" tab in developer tools, in blue. Look at its tag and construct a locator accordingly.
I learned the above trick myself.
With that said you can locate the username field using this xpath
'//input[@id="spark-input_38"]'(or by using id"spark-input_38").The id of the password field is
"spark-input_39".See the screenshot, the element above the one highlighted in blue is the username input field.
I have fixed your code:
Please actually try to learn programming and don't just copy crap from large language models, they aren't artificial general intelligence and don't have reasoning capabilities and absolutely can't write correct code.