I have a Selenium service that has to login to my gmail account as the first step. This functionality was working couple of weeks ago, but suddenly the login starts to fails and i am seeing this Error in browser, tried both in Chrome and Firefox drivers in selenium -
This Error comes after the selenium service inserts the email,password and clicks on the sign in button. A similar error was also reported in Google support Forum here- https://support.google.com/accounts/thread/10916318?hl=en, They said that "Google seems to have introduced automation tools detection on their login flow!" but there is no solution in this thread.
Some Other Details which might be useful-
I am not able to login manually to Google accounts in the browsers
opened by Selenium.
But I am able to login manually to these accounts in the Google
Chrome application.
Let me know if you need to take a look at the code, i will post it here.
Thanks in Advance!
Edit
Adding Sample code to refer.
public void loginGoogleAccount(String emailId, String password) throws Exception {
ChromeOptions options = new ChromeOptions();
options.addArguments("--profile-directory=Default");
options.addArguments("--whitelisted-ips");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("--disable-plugins-discovery");
WebDriver webDriver = new ChromeDriver(options);
webDriver.navigate().to("https://accounts.google.com");
Thread.sleep(3000);
try {
WebElement email = webDriver.findElement(By.xpath("//input[#type='email']"));
email.sendKeys(emailId);
Thread.sleep(1000);
WebElement emailNext = webDriver.findElement(By.id("identifierNext"));
emailNext.click();
Thread.sleep(1000);
WebDriverWait wait = new WebDriverWait(webDriver, 60);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("identifierNext")));
Thread.sleep(3000);
WebElement passwordElement = webDriver.findElement(By.xpath("//input[#type='password']"));
passwordElement.sendKeys(password);
Thread.sleep(1000);
WebElement passwordNext = webDriver.findElement(By.id("passwordNext"));
passwordNext.click();
} catch (Exception e) {
LOGGER.info(String.format("No email/password field available or it is already logged in: [%s]: ",
e.getMessage()));
}
}
Toggle "Allow Less Secure App Access"
There is a setting on your account that you can toggle that may help with this. It is the "Allow Less Secure App Access". You should be able to visit the link below to toggle that setting if you are already logged into the gmail account you want to modify.
Link to change setting on google account:
https://myaccount.google.com/lesssecureapps
Further information(source):
https://support.google.com/accounts/answer/6010255
I just tried something out that worked for me after several hours of trial and error.
Adding args: ['--disable-web-security', '--user-data-dir', '--allow-running-insecure-content' ] to my config resolved the issue.
I realized later that this was not what helped me out as I tried with a different email and it didn't work. After some observations, I figured something else out and this has been tried and tested.
Using automation:
Go to https://stackoverflow.com/users/login
Select Log in with Google Strategy
Enter Google username and password
Login to Stackoverflow
Go to https://gmail.com (or whatever Google app you want to access)
After doing this consistently for like a whole day (about 24 hours), try automating your login directly to gmail (or whatever Google app you want to access) directly... I've had at least two other people do this with success.
PS - You might want to continue with the stackoverflow login until you at least get a captcha request as we all went through that phase as well.
This issue was because of the selenium chrome profile. Create a new chrome profile and logged into it with the email id with which you were facing the issue. Then Turn on sync.
With this chrome profile in place I can skip the login steps and directly do the main process. Use: Chrome Options to add newly created chrome profile as an argument.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("Binary path of the Chrome");
Hope this one helps you.
Check if your Chrome version is >= 79 and if so, downgrade to 78. Here's what I did (Windows):
I uninstalled "retail Chrome" which constantly kept upgrading itself to the latest version using sneaky tricks such as Google Chrome services that would check for updates in the background.
Even disabling those system services didn't help because retail Chrome also installs timer events that would re-enable said services in the middle of the night, so you'd wake up to a new version, and not even notice until things break.
I installed v78 from the "offline installer" found here, which doesn't seem to install any "helpful" auto upgrade features: https://www.neowin.net/news/google-chrome-780390470-offline-installer/
The above problem went away like magic. It appears that v79 has some anti-feature built in that calls home with information that allows Google to conclude that a bot is at work.
Hope this works for you... if not, you could invest a lot of time and create your own "Chrome simulator" by patching and compiling Chromium accordingly...
The only one solution which worked for me, just create fresh random google account, and that's it. Worked without any problems.
I fixed it by using selenium-stealth module and editing chromedriver.exe.
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium_stealth import stealth
chrome_options = Options()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--disable-logging')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
# for editing chromedriver exe so that its not detected(run only once)
with open("chromedriver.exe","rb") as d:
file_data=d.read()
file_data=file_data.replace(b"cdc_",b"tch_")
with open("chromedriver.exe","wb") as d:
d.write(file_data)
driver = webdriver.Chrome('chromedriver.exe',chrome_options=chrome_options,desired_capabilities=caps)
# for injecting js to that tab so that browser not detected
stealth(driver,languages=["en-US", "en"],vendor="Google Inc.",platform="Win32",webgl_vendor="Intel Inc.",renderer="Intel Iris OpenGL Engine",fix_hairline=True,)
driver.get("https://accounts.google.com")
time.sleep(3)
driver.switch_to.active_element.send_keys("myemail#gmail.com\n")
time.sleep(3)
driver.switch_to.active_element.send_keys("mypassword\n")
This works for me:
from selenium import webdriver
from time import sleep
username=raw_input("username: ")
password=raw_input("password: ")
driver=webdriver.Chrome('...')
driver.get('https://stackoverflow.com/users/signup')
sleep(3)
driver.find_element_by_xpath('//*[#id="openid-buttons"]/button[1]').click()
driver.find_element_by_id('identifierId').send_keys(username)
driver.find_element_by_id('identifierNext').click()
sleep(3)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_id('passwordNext').click()
sleep(2)
driver.get('https://mail.google.com/mail/u/0/#inbox')
I found a similar solution here.
I am automating the application using selenium which is enabled with SSO(VIDM) integration which will take my system domain name and password. The moment I hit the application URL, It will process the SSO(VIDM) and displaying the browser pop up with SSL certificate , OK button. I am unable to locate "OK" button as inspect is blocked for that pop up.
Manual Work Around noticed: Able to select that certificate from the pop up with out clicking okay button by placing the cursor in Chrome driver address bar and then perform enter using the system keyboard.Please see the image here
Add the below chromedriver option to launch specific profile.
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
ChromeDriver driver = new ChromeDriver(options);
Refer to chromedriver page for more information.
ChromeDriver Capabilities
The application I'm testing requires a login with the user's Google account. Every time I log in, it displays/requires that I select the 'Allow Access' button as if it doesn't remember that I have already added it to my list of Authorized Access for my Google account. This doesn't happen when I test manually, only when I'm running Selenium. Has anyone come across an issue like this or know of a solution? Thanks in advance.
WebDriver driver = selenium_driver.get(); // using chrome driver
baseUrl = defaults.getProperty("base_url"); // this is set to my localhost
helper.ConnectToURL(baseUrl);
When this started happening, I had been using Selenium 2.28.0--since then, I've updated to 2.31.0 but it's exhibiting the same behavior.
Disclaimer: This is currently not possible according to the ChromeDriver wiki. It states in the "Known Issues" section "Cannot specify a custom profile". (https://code.google.com/p/selenium/wiki/ChromeDriver)
At some point when it is fixed, I would suggest creating or using the default chrome profile that has your authorized access set that your test uses whenever it starts up.
According to the ChromeDriver wiki: "By default, ChromeDriver will create a new temporary profile for each session".
Checkout this post for more in depth information regarding capabilities: http://code.google.com/p/chromedriver/wiki/CapabilitiesAndSwitches
I do my work in .NET and Windows; my set up would look something like this:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("start-maximized");
chromeOptions.AddArgument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
ChromeDriver chromeDriver= new ChromeDriver(this.Environment.ChromeDriverLocation, chromeOptions);
If you are not limited to using Chrome for your tests you are able to create and use custom profiles using Firefox.
The application I am testing requires pop-up to be enabled. When a launch a new Firefox profile I get the browser message
Firefox prevented this site from opening a pop-up window
with a button on the right called Options. I can manually click the Options button and select to Allow popups from ....
Question is how can I use profile.setPreference to set to allow popups from my website and also not show this Firefox message?
You can save your current Firefox prifile with allowed popups and load it from file like in this case: https://stackoverflow.com/a/6830109/1165331
save you current working profile with popups via browser and loat it.
I need to click on a cancel button for a Java based application.
I am using IE Driver, Eclipse IDE and my application only supports IE.[i am scripting in Java]
Here is the situation,
Login to the application
There is a account session popup[confirmation box][js]
[The alert has the focus, user cannot focus the application]
Click on the cancel button
Now, i have logged in successfully but i am unable to handle the JS Alert window.So i am unable to write further scripts.
Kindly help me out !!!
If you're using Java, and you're using the Selenium WebDriver API, something like the following code should work:
driver.switchTo().alert().dismiss();
Alert handling has not been implemented for every driver, but it should work for IE.
Remember you can always find the Javadocs for the WebDriver API at this link.
To Handle Alert in IE, you need to set the capabalities for IE first:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability("ignoreProtectedModeSettings", true); //added this to ignore protecion mode setting so as to launch IE
driver = new InternetExplorerDriver(capabilities);
driver.get("url");
driver.switchTo().alert().dismiss(); //or
driver.switchTo().alert().Accept(); // accordingly