How to automate Windows authentication in Python with selenium-rc? - python

I am using python to write selenium-rc test code for my server code. The server application is written with ASP.NET and is configured with "Windows authentication". The execution steps of my python code look like the following:
Start python main()
Create the selenium instance (say sel)
Start the selenium by calling sel.start()
Open the target URL with the selenium instance via calling sel.open(url)
Windows authentication dialog box pops up at this time
sel.open(url) is, by default, set to time out in 30 seconds while the authentication process is pending for input of username and password.
At this point, I could not find any way through selenium-rc interface to make it recognize the pop up dialog box. I google around and find out that the selenium-rc interface (in python) is for http authentication only- not Windows authentication.
I have tried to use autoit within selenium but still without luck.
Can any of you shed some light on this?
Thanks in advance.
marvinchen

Selenium has issues recognizing that window (try to search HTTP Basic Authentification for more details about it)
Basically, only thing which kinda works is to put username and password into URL request itself. Assuming your application runs on http://example.com the new url should look like this:
http://username:password#example.com
This solution works for me, but only using Google Chrome as a default browser for testing

There is now way you can sort it out easy and at this point unless I have missed something last few months it will only be FireFox who can fix this for you.
Read this blog how to sort it out:
http://applicationtestingtips.wordpress.com/2009/12/21/seleniumrc-handle-windows-authentication-firefox/

Related

[Python][Web Scraping] is there a way to prevent cache clearing when executing my script and the browser opens up?

I m a newbie so I will try to explain myself in a way it makes sense.
I produced my first ever python script to scrape data from a web page I use regularly at work. It just prints out couple of values in the console that previously I had to consult manually.
My problem is that every time I execute the script and the browser opens up, it seems the cache is cleared and I have to log in into that work webpage using my personal credentials and do the 2 factor authentication with my phone.
I m wondering wether there is a way to keep the cache for that browser (if I previously already logged into the web page) so I don´t need to go through authentication when I launch my script.
I m using selenium webdriver and chrome, and the option I have configured are these (in screenshot below). Is there perhaps another option I could add to keep cache?
Current options for browser
I tried to find info in the web but so far nothing.Many sites offer a guide on how to perform login by adding lines of code with the username and the password, but I would like to avoid that option as I still would need to use my phone for the 2 factor authentication, and also because this script could be used by some other colleagues in the future.
Thanks a lot for any tip or info :)
After days browsing everywhere, I found this post:
How to save and load cookies using Python + Selenium WebDriver
the second answer is actually the one that saved my life; I just had to add this to my series of options:
chrome_options.add_argument("user-data-dir=selenium")
see the provided link for the complete explanation of the options and imports to use.
Adding that option, I run the script for the first time and I still have to do the login manually and undergo authentication. But when I run it for the second time I don´t need any manual input; the data is scraped from the web, the result is returned and no need any manual action from me.
If anybody is interested in the topic please ping me.
Thanks!

Python interact with webrowser (opend by a user)

I am searching for a way which allows me to interact with a webrowser (Firefox,Chrome/Chromium,Edge are the most important).
I am currently using pyautogui, to locate login,password fields to put the login data into them. But since you can extract much easier informations when you can use IDs or xPath or other identifiers on webpages, it would make sense to use that.
I tried Firefox with selenium but I run in some problems. Can I attache it to a user created session (do I need the processID or something like that?). (Can I choose between the normal private session of the current profile?
I need a solution which works on Windows and Linux(it would be nice if the major Linux distros would support it. But the most important distros are Fedora/Ubuntu for me.) mac would be optional but since I do not got any mac I am not able to test it anyway.
The way with debugger mode or similar does not work really well for me since the browser needs to get started in a special way.
Would it possible to use something like this:
Can Selenium interact with an existing browser session? ,
When I can retrieve the this information some how form the existing browser?
driver.command_executor._url
driver.session_id
(But when I understand that currently it only works with browsers started with selenium?)
When I use Selenum and start a browserwindow with it can I login to a website and the user is logged in on the webside on his browser window too(if they us the same profile)? (Or does selenium separate cookies?)
If you need additional information or have some hints please post them so I can see them.
Thank you in advance for your help
It seems that it is not possible to connect to a web browser which was opened by the user to my understanding. How ever I found two possible solutions which I am currently trying to evaluate.
Using pyautogui to access the web browser over scanned images and control it with keyboard and mouse. (It is possible to access the console with the right combinations too).
The other solution is maybe more stable. Writing an browser extension which controls the browser.

Can I declare 2 desired_cap in 1 script? One for hybrid app and one for the Chrome app?

I have a hybrid app with redirects on the chrome browser.
In order to make appium recognize both apps, is there a possibility to declare a double desired_cap?
I want to make the script to click on one of the hybrid app button, then after the redirect to chrome is done, a verification of the chrome page should be done (so we can know that the redirect was done correctly) and then we have the driver.back() which will lead us back to the hybrid testing app.
I know is wrong what I've wrote, but can't find the right way.. got the error that the __second__ is not defined.
My example:
Can anyone help me with that? Thanks in advance.
You don't need to change the Desired Capabilities and also it is not possible during the session.
You must switch between the context of session (WEB_VIEW or NATIVE):
When the chrome opened do this:
driver.switch_to.context['WEB_VIEW_chrome]
Check your verifications and then you can change the context to the Native to continue on your android application:
driver.switch_to.context['NATIVE_APP]
Here is my full answer on this:
https://stackoverflow.com/a/62284044/7302505

How to use pywinauto and selenium for login purpose?

I tried to write code to login using pywinauto and selenium, but my script is getting failed. I tried to find solution, but it seems there is no much info available on this.
from pywinauto import application
from selenium import webdriver
driver=webdriver.Chrome()
app=application.Application()
driver.get("https://google.co.in")//url for google only as an example
app = application.Application()
app.connect(backend="uia") // getting issue in this line, what to write under bracket to connect to opened browser?
app.window_().TypeKeys('username') // Is this proper way to type text in authentication window username field where cursor blinks by default?
I am getting below error message
pywinauto.findwindows.ElementAmbiguousError: There are 6 elements that
match the criteria {'backend': u'win32'}
Note : For login to my application, windows authentication popup appears which cannot be handled in selenium, so need to handle it using other tool. I had a solution to it earlier which is not working now, I had asked it here Windows authentication code no longer working now
The steps your need are; open the page, find the elements you want to interact with (such as login text box) then type your input. This can all be done in selenium. Check out the documentation:
http://selenium-python.readthedocs.io/navigating.html#interacting-with-the-page

Determine current Mac Chrome web page using Python

Is there a way to determine programmatically, using Python, which web page is currently active in Google Chrome?
Google Chrome for Mac has added the AppleScripting method for getting the URL.
Here's the Chromium AppleScript SDK
https://sites.google.com/a/chromium.org/dev/developers/design-documents/applescript
Example from the page linked below:
tell application "Google Chrome"
get URL of active tab of window 1
end tell
More examples here:
http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html
Not yet, it seems. Such tasks are done, with other browsers, via the Applescript interface, but, as this thread shows, while hotly requested for Chrome on the Mac this feature is not there yet.
(Once a Mac app does get a good Applescript interface, there are several ways to use that interface from Python, without needing to actually involve Applescript as a language -- this has been touched upon on other SO questions about other apps -- but the problem is that Chrome in particular doesn't yet support this quintessentially Mac-ish functionality).
Given the insistence of the request I'd expect somebody to eventually roll up their sleeves and contribute a patch for the purpose, but it doesn't seem to have occurred yet.

Categories

Resources