Click Chrome prompt box to save password - python

I've just started using Selenium and implemented the ChromeDriver, but when going to the page I want, chrome gives it own prompt box, similar to " save password for this site always", it pretty much has the site asking to store data on my pc, and I have to verify that.. but it interferes with my script.
Is there anyway for Selenium to click " OK "? or am I able to import some sort of session ID so it's already allowed permission to save files rather than prompt me everytime?

First, I don't think this can interfere with the tests in any way, because it's a browser level thing. " it pretty much has the site asking to store data on my pc, and I have to verify that.", wrong. It has nothing to do with "save files". You don't need to worry about this prompt at all.
Second, I somehow can't reproduce your issue, so I can only provide the logic as below.
Chrome has a switch called "--enable-save-password-bubble", which enables save password prompt bubble. You can try set it to false when starting your Chrome.
# untested code, only the logic
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--enable-save-password-bubble=false")
driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)

Related

Website says my browser is out of date when I try to automate my login process with Selenium

This is my first stackoverflow post so please excuse any posting nuances I may fail to observe. The issue I'm running in to is regarding automating a login process to my credit card website using Selenium and Python (v 3.11). My overall goal is to simply login to my credit card website (Discover CC website), navigate to a "statements" page, download my current statement as a CSV file, and further manipulate it with other Python code, and run this on a scheduled basis (thinking once a week). However I'm stuck at the automated login process. The Discover site tells me my browser is out of date, which can lead to security risks and that my account is temporarily unavailable. This is currently where I'm stuck.
What I've tried so far is shown in the code attached below. Lines 18 and 20 were of course removed for security reasons, but contain my correct username and password for the website.
#import stuff
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
s = Service('C:\Program Files (x86)\chromedriver_win32\chromedriver.exe')
opts = Options()
opts.accept_insecure_certs = True
# opts.add_argument("--headless")
# assert opts.headless # Operating in headless mode
browser = Chrome(service=s, options=opts)
browser.get('https://portal.discover.com/customersvcs/universalLogin/ac_main')
browser.implicitly_wait(10)
time.sleep(3)
userID = browser.find_element(By.ID, 'userid-content')
userID.send_keys('myUserName')
password = browser.find_element(By.ID, 'password-content')
password.send_keys('myPassword')
browser.implicitly_wait(10)
time.sleep(3)
# userID.submit()
clickSubmit = browser.find_element(By.ID, 'log-in-button')
browser.implicitly_wait(10)
clickSubmit.submit()
When I run this, it takes me to the correct website in the expected browser (Chrome), for which I have downloaded what I believe to be the correct chromedriver (Chrome version is a 109.0.5414.120, chromedriver is a 109.x.xxxx.xxx release number as well, but didn't match version of Chrome exactly), and it correctly enters my username and password, but gives me an "need to update browser"-esque error.
What I'm trying to iron is:
Is there an issue with my code that I'm using / how I'm accessing the site?
Is this a cookies/SSL certificate issue where I just need to make my browser "think" I'm a real user instead of some automated test software like it states is controlling chrome in a banner at the time when it launches using this code?
Is this code performing as it should, it's just the anti-bot security of this website, given it's a CC/financial website, that's just really good at detecting bots and keeping them from logging in to their site, even when presenting the correct username/password on the first attempt.
I've tried the same method above but with other libraries (e.g. undetected_chromedriver, selenium-stealth) and have the same result/issue, with the exact error message of:
"Your account cannot currently be accessed.
Outdated browsers can expose your computer to security risks. To get the best experience on Discover.com, you may need to update your browser to the latest version and try again.
For questions, please contact us at 1-800-347-7769. We're always available 24 hours a day, 7 days a week."
Thank you for any/all help and input you all may have, I'm also a novice when it comes to Python/HTML, so apologies if this is an obvious issue/answer, I was using this idea solely as a learning opportunity.
Thanks!
Without the proper error stacktrace and/or access to the relevant HTML it is tough to comment on the error:
Your account cannot currently be accessed. Outdated browsers can expose your computer to security risks. To get the best experience on Discover.com, you may need to update your browser to the latest version and try again.
However as per support.mozilla.org and reddit it appears as a discover.com site issue.
Improvements
Having said that there are a couple of improvements which you can incorporate as follows:
Replace the instances of browser.implicitly_wait(x) and time.sleep(y) with WebDriverWait
Locate the clickable elements inducing WebDriverWait for the element_to_be_clickable() as follows:
driver.get('https://portal.discover.com/customersvcs/universalLogin/ac_main')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userid-content"))).send_keys("SageHerrin#stackoverflow.com")
driver.find_element(By.CSS_SELECTOR, "input#password-content").send_keys("SageHerrin")
driver.save_screenshot("login.png")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:

I am using Google Chrome with Selenium and while going on Amazon, it detects it and Blocks everything. Can I bypass this?

This is tied to my other question here: Selenium cant seem to find Amazon "Pre-order now" button. Python
It worked for a bit but now when I run the code, it detects the robot and shows me the DOG image even after I enter in the captcha text. Please help.
I am not sure if this will help, But I would suggest you to open browser every time in incognito mode.
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
driver = webdriver.Chrome(executable_path = driver_path, options = options)
I think I found the solution.
I deleted the Chromdriver.exe from where I had it downloaded and that fixed everything.

How to open browser with all credentials and settings already loaded

Hope everyone is doing okay 😊
Currently I’m trying to get info from a page where I have to sign in and then complete a Captcha (selecting different pictures) in order to proceed. The thing is that when I enter the page from my default browser (like manually clicking chrome) I don’t need to sign in and complete the captcha, because I am already signed in (I think because of the cookies?).
Every time I run selenium it opens a “blank” Chrome, is it possible to open a browser with all my data already loaded in order to skip the captcha?
I have tried different solutions explained here but with no success How to save and load cookies using Python + Selenium WebDriver
Thank you very much!
Yes there is a way: You can load your Chromebrowser with the chrome-profile saved on your computer. To do this you have to use webdriver.Chromeoptions().
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\YourUser\AppData\Local\Google\Chrome\User Data\')
PATH = "/Users/YourUser/Desktop/chromedriver"
driver = webdriver.Chrome(PATH, options=options)
In your chrome-user, every cookie and stuff is saved and you no longer have a clean browser. Remember: There are still websites which can detect that your using selenium, but there are only a few...

How can I get rid of the message "This connection is not secure..."?

I have an automated test which fills the User + Password fields and click a certain button to Login.
During the development session I managed to run this automation tens of times without any problem. Suddenly today I found out that the response to the automated test has changed and now I can't Login. I can say that the WEB under test didn't change. I can almost tell for sure that the FireFox that is run by the automated test has updated without my control (the browser that the automated test runs has an up-to-date version 54 while the browser that I run has a version 52).
I have tried to configure the Version 54 so that he won't pop-up the message (through the about:config) but my settings are not saved.
First of all I would like to know how can I manage to get rid of the pop-up message ?
Second thing I would like to know how can I prevent the updates of the browser version ?
Could it be that the geckodriver has its own FireFox settings and Version ?
Firstly, you can configure FirefoxProfile to accept untrusted connections, as shown below:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
driver = webdriver.Firefox(firefox_profile=profile)
This answer contains configuration details about other browsers as well.
Secondly, in order to disable automatic updates for Firefox browser, you can follow following steps:
Launch Firefox and go to 'Tools->Options->Advanced'.
Click on 'Updates' tab.
Click on 'Never Check for updates' option button under 'Firefox updates' section.
Restart Firefox.
Let me know, if it resolves your issue.
You need to set acceptInsecureCerts to true in your capabilities.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.MARIONETTE, true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
WebDriver webDriver = new FirefoxDriver(capabilities);
Edit: Sorry about the java code. The thing is you need set that capability.

How to use acceptSslCerts with RemoteWebdriver?

I am trying to force selenium to ignore SSL errors, but haven't been able to figure it out. I have seen acceptSslCerts capability, but it does not seem to have any effect when using firefox
For your scenario, you can try something similar to this. It worked well for me on Firefox browser.
Create new firefox profile by following below step and accept SSL certificates there.
Close all your firefox windows
In the Run dialog box, type in: ‘firefox.exe -p' and then Click OK.
Click “Create Profile”
Create a name for your new profile(say Selenium)
Click “Choose Folder”
Pick something easy to find — like “C:\NewFirefoxProfile”
Click Finish
Now after selecting newly created profile, start Firefox. Open the specific url you were getting 'Secure Connection Issue', accept SSL certificates for this profile
Now use the newly created firefox profile to run your selenium test. Modify below code as per your requirement.
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
profile.assume_untrusted_cert_issuer=True
driver = webdriver.Firefox(firefox_profile='C:/NewFirefoxProfile)
driver.get('https://cacert.org/')

Categories

Resources