You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Selenium ChromeDriver启动Chrome以保留登录状态?

Fixing the FUT Web App Login Verification Code Issue in Selenium

Hey there! I totally get where you're coming from—dealing with that extra verification code every time you run your Selenium script is a real pain, especially when your regular Chrome session skips it no problem. Let's break down why this happens and how to fix it.

Why the Verification Code Pops Up

By default, Selenium launches Chrome with a fresh, temporary user profile—no saved cookies, no trusted device settings, none of the stuff your regular Chrome session uses. EA's systems see this as a new, untrusted device, so they force the verification code. Your normal Chrome uses your personal user profile, which EA has already marked as trusted after you verified it once, hence no code needed.

The Solution: Use Your Local Chrome User Profile

The fix is to make Selenium load your existing Chrome user profile instead of a fresh one. Here's how to do it step by step:

1. Locate Your Chrome User Data Directory

First, find where Chrome stores your user data:

  • Windows: C:\Users\<YourUsername>\AppData\Local\Google\Chrome\User Data
  • Mac: ~/Library/Application Support/Google/Chrome
  • Linux: ~/.config/google-chrome

2. Configure ChromeOptions in Your Code

Add code to tell Selenium to use your user profile. Here's how to modify your existing Java code:

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.By;

public class FUTLogin {
    public static void main(String[] args) {
        // Set ChromeOptions to use your local user profile
        ChromeOptions options = new ChromeOptions();
        // Replace <YourUserProfilePath> with the path you found earlier
        // Example for Windows: "C:\\Users\\JohnDoe\\AppData\\Local\\Google\\Chrome\\User Data"
        options.addArguments("user-data-dir=<YourUserProfilePath>");
        // Use the "Default" profile (or your custom profile name if you have one)
        options.addArguments("profile-directory=Default");

        // Initialize driver with the configured options
        ChromeDriver driver = new ChromeDriver(options);

        String baseUrl = "https://www.easports.com/fifa/ultimate-team/web-app/";
        driver.get(baseUrl);
        driver.manage().window().fullscreen();
        
        // IMPORTANT: The first time you run this, you might still see the verification code
        // Complete it manually and make sure to check "Remember this device"
        // Subsequent runs should skip the code
        
        // You may not even need the login code below anymore if your profile is already logged in!
        Thread.sleep(10000);
        WebElement login = driver.findElement(By.xpath("//*[@id='Login']/div/div/div[1]/div/button"));
        login.click();
        Thread.sleep(2000);
        WebElement email = driver.findElement(By.xpath("//*[@id='email']"));
        email.sendKeys("******@hotmail.com");
        Thread.sleep(1000);
        WebElement password = driver.findElement(By.xpath("//*[@id='password']"));
        password.sendKeys("*******");
        WebElement loginButton = driver.findElement(By.xpath("//*[@id='btnLogin']/span"));
        loginButton.click();
        Thread.sleep(10000);
    }
}

3. Important Notes

  • Close all Chrome windows before running the script: Chrome doesn't allow multiple instances to use the same user profile at the same time—this will cause errors if you have regular Chrome open.
  • First run setup: The first time you launch Selenium with your profile, you may still get the verification code. Complete it, make sure to check "Remember this device", and then close the driver. Next time you run the script, EA will recognize the trusted profile and skip the code.
  • Optional: Use a dedicated profile: If you don't want to mix your personal browsing data with Selenium, you can copy your Default profile folder to a new location (e.g., Chrome/User Data/SeleniumProfile) and use that path instead. This keeps your main profile untouched.

Why This Works

By loading your existing user profile, Selenium inherits all the saved cookies, session data, and trusted device flags that EA's servers recognize. It's just like using your regular Chrome browser—so the verification code won't be required anymore (after the initial setup).

内容的提问来源于stack exchange,提问作者user2958268

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:32:50