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.
webdriver_path = r'C:\Program Files (x86)\chromedriver.exe'
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:
'"C:\Program Files (x86)\chromedriver.exe"' is not recognized as an internal or external command,
operable program or batch file.
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 chromedriver
first, 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:
driver = webdriver.Chrome(executable_path= r'C:\Program Files (x86)', options=options)
r'C:\Program Files (x86)'
needs to be the actual chromedriver path, use webdriver_path
here. For example, mine's path is "D:\CliExec\chromedriver.exe"
.
So if I were to use the above syntax, I would do:
driver = webdriver.Chrome(executable_path= r"D:\CliExec\chromedriver.exe", options=options)
But you don't actually need to explicitly pass the paths as arguments. selenium
automatically finds it for you.
Just do webdriver.Chrome()
. And if that doesn't work, make sure chromedriver.exe
is downloaded, find its path, put the folder it is inside in PATH environment variable. Google if necessary, again.
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
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:
driver.get('https://sph.synxis.com/pms-web-ui/login#/logout-success')
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.
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')
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:
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
username = 'xxxxxx'
password = 'xxxxxxxx'
driver = webdriver.Chrome()
driver.get('https://sph.synxis.com/pms-web-ui/login')
wait = WebDriverWait(driver, 10)
username_input = wait.until(EC.presence_of_element_located((By.ID, "spark-input_38")))
password_input = driver.find_element(By.ID, "spark-input_39")
username_input.send_keys(username)
password_input.send_keys(password)
password_input.send_keys(Keys.RETURN)
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.