Automatically login gmail with selenium webdriver but when I close the browser and open it again normally, even I use selenium webdriver go to gmail, I must login again. Why?
This is my code
from selenium.webdriver.firefox.options import Options
from selenium import webdriver
import time
fp = webdriver.FirefoxProfile (r"K:\Desktop\Kiranaf\Profile")
options = Options()
options.set_preference('media.peerconnection.enabled', False)
options.set_preference('javascript.enabled', False)
driver = webdriver.Firefox(firefox_profile = fp,options = options)
driver.get("http://gmail.com")
...
Thanks for reply my question !!! :(
Related
webdriver_manager site has a code to start webdriver with brave, but instead of brave it opens it with google chrome. My selenium version 4.6.0 gave the following code for selenium 4 (I also tried the given codes for selenium 3) as it can be seen on the site, but the webdriver still opens with chrome
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as BraveService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
driver = webdriver.Chrome(service=BraveService(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()))
driver.get("https://pypi.org/project/webdriver-manager/")
Okay, so you just want to start a driver with Brave browser instead of chrome? Here is how I do that simplely, keep in mind I'm on Mac. You need the binaryPATH to the application.
add_block_ext = "Path to .crx extension"
driverPath = 'chromedriver'
binaryPath = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
options = webdriver.ChromeOptions()
options.binary_location = binaryPath
options.add_extension(add_block_ext)
browser = webdriver.Chrome(executable_path=binaryPath, chrome_options=options)
browser.get("https://www.google.com")
I'm trying to open chrome browser with password session in python3 and Selenium
Here is my code :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options();
options.add_argument(r"--user-data-dir=/home/username/.config/google-chrome/")
options.add_argument(r'--profile-directory=User Profile')
service = Service('/opt/google/chrome/chromedriver')
driver = webdriver.Chrome(service=service, options=options)
It's open my chrome with my profile but delete all cookie and password connection.
How i can open chrome with my saved password and session ?
You're using linux, try undetected chromedriver as webdriver
I am running a basic python program to open the Chrome Window but as soon as the code executes, the window is there for a sec and then it closes immediately.
from selenium import webdriver
import time
browser = webdriver.Chrome(executable_path=r"C:\APIR\chromedriver.exe")
browser.maximize_window()
browser.get("https://www.google.com")
Chromedriver version: 91.0.4472.101
Chrome Version: 91.0.4472.164
Any help would be appreciated.
Thank you
It closes because the program ends.
You can:
Wait with time.sleep, for example time.sleep(10) to keep the browser open for 10 seconds after everything is done
Have the user press enter with input()
Or detect when the browser is closed. Many ways to do that.
Example: https://stackoverflow.com/a/52000037/8997916
You could also catch the BrowserUnreachable exception in a loop with a small delay
For Edge Browser
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
options = webdriver.EdgeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Edge(options=options, service=Service(EdgeChromiumDriverManager().install()))
driver.maximize_window()
driver.get('https://stackoverflow.com/questions/68543285/chrome-browser-closes-immediately-after-loading-from-selenium')
For Chrome Browser
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options, service=Service('./path/to/chromedriver'))
driver.maximize_window()
driver.get('https://stackoverflow.com/questions/68543285/chrome-browser-closes-immediately-after-loading-from-selenium')
I have a code for making temp mail automatically but I have a problem.
This is code:
import time
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://temp-mail.org/")
time.sleep(10)
browser.close()
The link opens correctly but I can't pass cloudflare.
Also, I see some errors on my console:
Thanks...
Try adding user agent argument in chrome options and set user agent to any value
ops = Options()
ua='me'
ops.add_argument('--user-agent=%s' % ua)
driver=uc.Chrome(executable_path=r"C:\chromedriver.exe",chrome_options=ops)
Alternatively try using undetected-chromedriver
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = uc.Chrome(options=options)
driver.get("https://temp-mail.org/")
While running my python selenium script for firefox browser; I encountered an issue saying
Your connection is not secure
It is not allowing me to Add exception and blocked
Confirm Security Exception
as well (even with preferences manually). hence i am trying to add profiles like "webdriver_accept_untrusted_certs", "webdriver_accept_untrusted_certs" but nothing is helping me out. Not sure how to tackle this...
I need some help here
Currently using the following...
Python 3.4.4
selenium==3.4.1
linux 32 bit
Firefox 60.6.1esr (32-bit)
Everything seems to be compatible, so no issue here.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().FIREFOX
profile = webdriver.FirefoxProfile()
profile.set_preference("webdriver_assume_untrusted_issuer", False)
profile.update_preferences()
browser = webdriver.Firefox(capabilities=cap,firefox_profile=profile)
browser.get('my url')
and
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().FIREFOX
profile = webdriver.FirefoxProfile()
profile.set_preference("webdriver_accept_untrusted_certs", True)
browser = webdriver.Firefox(capabilities=cap,firefox_profile=profile)
browser.get('my url')
I want to get rid of the "Your Connection is not secure"
For FireFox you can use:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_caps = DesiredCapabilities.FIREFOX.copy()
desired_caps.update({'acceptInsecureCerts': True, 'acceptSslCerts': True})
driver = webdriver.Firefox(capabilities=self.desired_caps)
For Chrome:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-ssl-errors=yes')
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(options=options)