Setting Chrome profile in Selenium doesn't bypass Microsoft MFA - python

I'm trying to incorporate scraping data from the AWS management console into an automation script, and for some reason my company's AWS is behind a Microsoft multi-factor authentication system. This isn't an issue when going to the console link manually, as the browser remembers that in the past I've already gone through the MFA process and I am directed right to the console. When navigating to the same link in Selenium I am instead brought to the MFA page asking my permission to text/call my phone.
I learned that this could be solved by setting Chrome Profile in the Webdriver options.
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/Users/myuser/Library/Application Support/Google/Chrome/")
Even after setting this I am still redirected to the MFA page every time. Am I going about this the wrong way? Is there an easy way to check if the Chrome Profile is actually working as expected?

You need to use an actual user data dir not just the folder where the general chrome data is stored.
For the default chrome profile the name would be:
"/Users/myuser/Library/Application Support/Google/Chrome/User Data/Default"

//Add argument and provide path to userdata
Remember to change username to your username.
Option.AddArgument("user-data-dir=c:\Users\~username~\AppData\Local\Google\Chrome\Userdata");
//Add whatever profile number that corresponds to session you want to open
Option.AddArgument("--profile-directory-Profile-10");
*Find profile by using chrome://version flag in session you want to use. The flag will tell you profile number.

Related

Why doesnt Selenium/Chrome Driver open websites with me auto logged in

You guys know how google keeps you signed into different websites? how come whenever I use Selenium/Chrome driver and have it go to a website I'm already signed into, it is like im a fresh user and I have to have Selenium go through the work of signing in, which in some cases I cant because some websites block me from signing in with selenium because they know I'm using a bot.
Google keeps you signed into different websites through your Default profile.
Where as Selenium driven ChromeDriver initiated google-chrome Browsing Context is opened everytime with a newly crated temporary profile.

How to make chromedriver open chrome open as a new user in python programatically

I have a use case for my client where we want to perform test automation using Selenium in python and behave framework.
Now the client website is actually behind an Azure AD Authentication. So for example I am logged into a machine as user ABC, and I try to access the website it will log me in with that user. But if I want to login with another user id for ex: XYZ this will still login to ABC. To avoid this from happening we need to right click on chrome and say start chrome as another user. This will then give a popup for username and password with an attached domain.
So I want to ask is there any way we can do this programmatically using selenium web driver python code. I.e. is there any way to start chrome as another user programatically where I can specify the domain,username and password.

how to work on a exist session in selenium with python?

I want to fill some field of a webpage and then send a request to it
but this website has a very powerful login page to avoid sending requests for login from a robot
so I can't log in with selenium but after login, I can use selenium and I can send requests, on the other hand, I write this program for an app so I can't open a web driver and then work on it
I need to work on a tab that exists
I want to program work on a session that a human opened
From what I understand from your question is that you want to open an existing browser that is launched by a human.
There are multiple ways to achieve this and as mentioned by Devansh in the comment, You can use the session ID to get the already launched browser and execute your test script on it.
However, there is another way that might be able to solve your issue of executing scripts on already open connection or logged in user.
You can use the profiles of browsers for this scenario, User profiles in a browser are like user accounts on a computer.
You can use the answer to this question to create and use profiles in your script:
Opening an existing tab/logged in user using Chrome Webdriver
Now You can manually log in the required account for the website on the above profile you are struggling to log in and then launch the scripts.

How to handle browser or app may not be secure issue with web driver Selenium python?

I'm trying to automate sign in into gmail and I get to see this error.
I think this must be because the website is able to detect the automation and blocking it. Can you all please tell me how to overcome this?
I don't see this issue with my personal account but this happens only with a common account.
In you account profile, in Security options, try setting this option:
This issue was because of the selenium chrome profile.
I have created a new chrome profile and logged into it with the email id with which I was facing this 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.
Hope this helps people who are facing similar challenge.
I faced this issue.
I have created dummy gmail account and now my selenium script is working fine for the same and able to login successfully.
it's not working for my personal gmail account.
Thanks !!

selenium webdriver python: opening chrome browser to run test case does not load the saved settings of the browser

I am trying to run a selenium test case in Chrome browser. Before this i have set the default download location for files of chrome browser to say f:/xyz
When the selenium script is run, which clicks on a link to download a file - it downloads in the chrome's default location (c:/documents and settings/downloads) and not in the f:/xyz which i have set earlier
How to correct this ?
More than likely, the problem here is that the download location is associated with a specific user profile, and the Chrome driver follows the same pattern as the Firefox driver in that by default, it uses a copy of a completely clean user profile every time it is run, so the download location you set for your user is never picked up by Selenium. In Firefox, the solution is to create a custom Firefox profile, then tell Selenium to run with that. I'd bet there is an analogous function in the Chrome driver.
According to docs:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/path/to/profile/directory"));
WebDriver driver = new ChromeDriver(capabilities);
Yes that is Java, but it should be fairly easy to translate to Python. Also, note the docs say that there is a known bug about being able to set a custom profile.
Edit:
I think I found a mildly hacky solution that should work for you.
Go to the master folder that contains user/home folders on the OS you are running under
Under the SYSTEM user folder, find the Chrome user data directory
Open the Preferences file (it's raw text, so any text editor will work)
Under the "download" node, create or modify the "default_directory" node to be whatever download location you want
Note that these steps assume that Selenium has actually run Chrome at least once under the SYSTEM user. If not, you can manually create the directories needed by running Chrome under the SYSTEM user yourself, from the terminal for instance.
It can't be done at the time. From the official ChromeDriver Wiki at http://code.google.com/p/selenium/wiki/ChromeDriver:
Known Issues
There are a handful of known issues with ChromeDriver, listed below:
Can only retrieve the name and value of set cookies (no domain, path, etc.)
Typing does not work with rich-text enabled documents.
Cannot specify a custom profile
HTML 5 API not implemented

Categories

Resources