SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.77k stars 8.2k forks source link

[🐛 Bug]: Title: Bypass "This browser or app may not be secure" issue in Selenium with Firefox Body: I am trying to automate login to a Gmail account using Selenium with Firefox browser. However, I am facing the issue where it says "This browser or app may not be secure". Here is the code I am using: <Include your code here> I have tried using undetected_chromedriver, but it only supports Chrome. How can I bypass this issue with Firefox? Any help would be appreciated. Error Message: <Include the exact error message you are getting> Thanks in advance! #14326

Closed Azedize closed 3 months ago

Azedize commented 3 months ago

What happened?

Title: Bypass "This browser or app may not be secure" issue in Selenium with Firefox

Body: I am trying to automate login to a Gmail account using Selenium with Firefox browser. However, I am facing the issue where it says "This browser or app may not be secure".

Here is the code I am using:

I have tried using undetected_chromedriver, but it only supports Chrome. How can I bypass this issue with Firefox? Any help would be appreciated. Error Message: Thanks in advance! ### How can we reproduce the issue? ```shell Title: Bypass "This browser or app may not be secure" issue in Selenium with Firefox Body: I am trying to automate login to a Gmail account using Selenium with Firefox browser. However, I am facing the issue where it says "This browser or app may not be secure". Here is the code I am using: I have tried using undetected_chromedriver, but it only supports Chrome. How can I bypass this issue with Firefox? Any help would be appreciated. Error Message: ehenry01 ``` ### Relevant log output ```shell from seleniumwire 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.common.exceptions import ElementNotInteractableException, TimeoutException import gc import time def read_user_data(file_path): users = [] try: with open(file_path, 'r') as file: for line in file: email, password, proxy_host, proxy_port, proxy_user, proxy_pass = line.strip().split(';') users.append({ 'email': email, 'password': password, 'proxy_host': proxy_host, 'proxy_port': proxy_port, 'proxy_user': proxy_user, 'proxy_pass': proxy_pass }) except FileNotFoundError: print(f"File '{file_path}' not found.") except Exception as e: print(f"Error reading '{file_path}': {str(e)}") return users def set_window_size(driver, width, height): driver.set_window_size(width, height) print(f"Set window size: {width}x{height}") def create_firefox_profile(proxy_host, proxy_port, proxy_user, proxy_pass): profile = webdriver.FirefoxProfile() profile.set_preference("network.proxy.type", 1) profile.set_preference("network.proxy.http", proxy_host) profile.set_preference("network.proxy.http_port", proxy_port) profile.set_preference("network.proxy.ssl", proxy_host) profile.set_preference("network.proxy.ssl_port", proxy_port) profile.set_preference("network.proxy.no_proxies_on", "localhost,127.0.0.1") profile.set_preference("browser.safebrowsing.enabled", True) profile.set_preference("privacy.clearOnShutdown.cookies", True) profile.set_preference("privacy.clearOnShutdown.history", True) profile.set_preference("privacy.clearOnShutdown.offlineApps", True) profile.set_preference("privacy.sanitize.sanitizeOnShutdown", True) profile.set_preference("dom.webdriver.enabled", False) profile.set_preference("useAutomationExtension", False) return profile def test_login(user): proxy_options = { 'proxy': { 'http': f'http://{user["proxy_user"]}:{user["proxy_pass"]}@{user["proxy_host"]}:{user["proxy_port"]}', 'https': f'http://{user["proxy_user"]}:{user["proxy_pass"]}@{user["proxy_host"]}:{user["proxy_port"]}', 'no_proxy': 'localhost,127.0.0.1' } } firefox_profile = create_firefox_profile(user["proxy_host"], int(user["proxy_port"]), user["proxy_user"], user["proxy_pass"]) firefox_options = webdriver.FirefoxOptions() firefox_options.profile = firefox_profile firefox_options.add_argument("--disable-blink-features=AutomationControlled") firefox_options.add_argument("--ignore-ssl-errors") firefox_options.add_argument("--ignore-certificate-errors") firefox_options.add_argument("--allow-insecure-localhost") driver = webdriver.Firefox(options=firefox_options, seleniumwire_options=proxy_options) # Adding stealth techniques driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") driver.execute_script("Object.defineProperty(navigator, 'plugins', {get: () => [1, 2, 3]})") driver.delete_all_cookies() driver.get("https://mail.google.com") driver.maximize_window() try: try: WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="gb"]/div[2]'))) print(f"User {user['email']} is already logged in.") driver.get("https://mail.google.com/mail/u/0/#inbox") except TimeoutException: try: account_selector = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, f"//div[text()='{user['email']}']")) ) account_selector.click() print(f"Selected existing account: {user['email']}") driver.get("https://mail.google.com/mail/u/0/#inbox") except TimeoutException: email_field = WebDriverWait(driver, 20).until( EC.presence_of_element_located((By.XPATH, '//*[@id="identifierId"]')) ) email_field.send_keys(user['email']) email_field.send_keys(Keys.ENTER) WebDriverWait(driver, 20).until( EC.presence_of_element_located((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')) ) password_field = WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')) ) password_field.send_keys(user['password']) password_field.send_keys(Keys.ENTER) WebDriverWait(driver, 30).until(EC.title_contains('Inbox')) print(f"Login successful for user: {user['email']}") premier_email = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.CSS_SELECTOR, 'tr.zA.zE')) ) premier_email.click() WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, 'div.a3s')) ) time.sleep(6) driver.delete_all_cookies() except ElementNotInteractableException as e: print(f"Element not interactable for user {user['email']}: {e}") except TimeoutException as e: print(f"Timeout occurred for user {user['email']}: {e}") except Exception as e: print(f"An error occurred for user {user['email']}: {e}") finally: driver.quit() gc.collect() users = read_user_data('C:/Users/tec-d/OneDrive/Bureau/Selenium python/Selenium python/index.txt') for user in users: test_login(user) ``` ### Operating System windows ### Selenium version Name: selenium Version: 4.22.0 Name: selenium-wire Version: 5.1.0 ### What are the browser(s) and version(s) where you see this issue? firefox 128 ### What are the browser driver(s) and version(s) where you see this issue? seleniumwire ### Are you using Selenium Grid? 4.00
github-actions[bot] commented 3 months ago

@Azedize, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] commented 3 months ago

💬 Please ask questions at:

github-actions[bot] commented 2 months ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.