how to work on a exist session in selenium with python? - 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.

Related

Is there any way to get text from an element on current browser in python?

the thing is I can login to the site only from one device, which is my browser so I can't use selenium, so I have to use something else which opens my browser and copy the text from an element using python.
I think that you may use one of two solutions:
use selenium to open a browser every time, and automate the login process.
If the site allows you to access without logging in when you access with your default browser(such as Stack Overflow for example - you don't need to login every time you open the website from your device), you can use the same browser profile and it should do the same job - login automatically to that website.
references:
what's a browser profile?
how to load a chrome's browser profile with python3 and selenium?

Setting Chrome profile in Selenium doesn't bypass Microsoft MFA

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.

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 keep log in credentials on Internet Explorer on Selenium

I'm currently working on a script that opens a URL and then click on buttons on a form in Internet Explorer specifically and repeat every x minutes. The problem I'm facing is that the website requires log-in credentials and it is not quite secure to hard code credentials inside the script.
The intention so far is to have Selenium open open a new tab inside an existing instance of IE that is already logged in. This would then allow the script to perform each time without having to enter credentials each time it runs.
How would I go about either doing the above and/or performing the same outcome (having selenium work on a IE instance with the log in credentials)

Use Existing Google Chrome Window To Web Scrape Python

Running Python 3.6 and I'm having a whole lot of issues logging to a site primarily due to captcha. I really only need to search up URLs and retrieve the html on the page but I need to be logged in for certain additional information to appear on the accessible URLs.
I was using urllib to read the URLs but now I was looking for a solution to login and then request information. The automatic route won't seem to work due to those issues, so I'm looking for a method by which I am already logged in on an open browser and python opens up new tabs to search for URLs (the searches can be hidden, they don't have to literally open up new tabs). It appears that when I open new tabs manually on the site it still shows i'm logged in so If i can manually log in each time i want to run the script and then work based off that, it would actually work just fine.
Thanks

Categories

Resources