-1

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()
CatChMeIfUCan
  • 569
  • 1
  • 7
  • 26
  • Please provide the full path to the chromedriver.exe -> filedriver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', options=options) – Samira Kumar Nanda Jul 23 '23 at 16:29

1 Answers1

0

I have strong evidence that your code is copied from ChatGPT:

enter image description here

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.

enter image description here

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.

Ξένη Γήινος
  • 2,181
  • 1
  • 9
  • 35
  • I looked at your code and ran it, GREAT, it worked and it was much simpler than what I was doing. I hope I didn't disappoint you too much using chatgpt. I am trying to automate a night audit I have to do for work every night here at a hotel. It's tedious because every night at 3 am I have to make sure everyone is checked in to the hotel regardless if they showed up or not, then I have to run the night audit, which moves the systems days ahead to the current one going on. Then I save the same reports to the same folders and email one set to management and the other I have use for accounting. – Fraz Naqvi Jul 29 '23 at 09:12
  • I use the inn-flow accounting software and it's a hassle because i get a report in a pdf format( i can get others) and then I manually enter one by one numbers into an excel like interface. – Fraz Naqvi Jul 29 '23 at 09:13
  • Sorry this was long, perhaps unneccessary, but I do have a question, after running your code, the SABRE website does open and enter credentials, but won't stay open for another moment. I was able to look up other people with the similar issue but the best thing I found was importing time and then using the sleep function to keep chrome open for a bit longer, but is their a way to open chrome, and login in permanently or at least as long as it would had I manually logged in. – Fraz Naqvi Jul 29 '23 at 09:16