When I open a page with selenium webdriver I get a chrome dialog box "Choose certificate". The default certificate is the right one so I only have to click OK button. But I have problem with this. I have python code:
drv = webdriver.Chrome()
drv.get("https://example.com/login")
and after that I want to do something like:
drv.switch_to_alert().accept()
or
drv.switch_to_alert().send_keys(Keys.TAB)
drv.switch_to_alert().send_keys(Keys.SPACE)
The problem is that the code stops executing on line drv.get("https://example.com/login"). Webdriver is waiting for page to load. And before that line there is no chrome dialog box.
How can I handle this?
You'll have to use something like AutoIT:
http://www.autoitscript.com/site/autoit/
Why you ask? It's an OS dialog, which Selenium does not and probably never will handle, so you'll have to turn to other solutions (in C# you should use native Win32 API methods to click the button for instance).
Certificates are managed by the OS, not the browser. Delete all but the necessary certificate from your browser's certificate store and then configure the browser to automatically select the certificate when only one certificate is present. You could also create a browser profile and have your program launch this profile or avoid testing over HTTPS.
before handling anything here, add below so it will not get frozen as soon as you navigate/triggert the certificate pop up. remeber to add the correct waittime back later.
getDriver().manage().timeouts().pageLoadTimeout(1000, TimeUnit.MILLISECONDS);
after this, then you can try using keyboard or autoIt whatever .
You can configure you Policys Group for Chrome choose your certificate.
Chrome use a registry with a json with information of your certificate. After you configure gpo,find a way to modified this json with Python.
With C# I use Microsoft.Win32.Registry to manipulates the registrys.
Follow the steps to configure you gpo:
First I need to thanks IngussNeilands for the tutorial provided on his Github. It saved me!
You can follow the steps on IngussNeilands´s tutorial here or follow my version of his tutorial below.
## Steps to Configure the Policy Groups
Download Chrome Policy Tamplates from here: http://dl.google.com/dl/edgedl/chrome/policy/policy_templates.zip
Extract the .zip file and find the chrome.adm that matches the country and the language settings on your Windows, following the path: policy_templates\windows\adm\<YourCountryAndLanguage>\chrome.adm
Type "run" into your Windows Search Bar or press Windows + R. Then type de command gpedit.msc to open the The Local Group Policy Editor
Now, access: 'Computer Policy>> Computer Configuration' and right-click the file 'Administrative Templates' and select 'Add or remove tamplates'
Click 'add' and navigate to the chrome.adm that you choose before on 'policy_templates\windows\adm\<YourCountryAndLanguage>\chrome.adm'. Click to open it
Now, navigate to:
'Computer Policy>> Computer Configuration>> Administrative Templates>> Classic Administrative Templates(ADM)>> Google>> Google Chrome>> Content Settings'
Then on the rigth side of the window find and double-click the option 'Automatically select client certificates for these sites'
Click the 'Enabled' option
Now, Click the 'Show...' in the option pane below
Copy and paste the 'JSON' below in the line of the column Value:
{"pattern":"https://[*.]example.com","filter":{"ISSUER":{"CN":"example.com"}, "SUBJECT":{"CN":"value"}}. This JSON needs to be rewriten with your certificate informations
How to rewrite the Chrome Configure JSON
Ok, now a will give you a brief explanation on how to rewrite the Chrome Config JSON.
In the "pattern" key the value needs to be the URL that the certificate will be sent to. In most cases this URL is the same URL of the page, but some sites don´t use the same URL base to send the certificate.
For example, when I was trying to webscraping the NFS-e in Uberlândia city I needed to debug the script of the page to find the URL to where the certificate was sent.
The "filter" key will have the certificate information. In my case, I need to access the same website with diferent certificates, for that I'll have to fill the JSON with the information of "ISSUER" and "SUBJECT". Chrome will choose one certificate that matches with the informations content in the filter key. For example, if I fill the "CN" from "ISSUER" object with "SERASA Certificadora Digital v5" I'll have more than one certificate with these informations and Chrome won´t be able to choose the right certificate.
In my git in here you can find the solution to alter the JSON for access the same site with more the one certificate.
Related
Example, qbittorent can be made to open links that are of torrent files.
Email clients mailto:
Is it possible to create links in a browser that will open the given file in Intellij? (Not full path, but entire package possibly ).
Idea is that this will be created for bitbucket.
There is an open feature request to add idea:// protocol handler.
At the moment it works on macOS only out of the box. For other platforms you can try the third-party solution or other workarounds from the ticket comments.
There is also a built-in web server providing the REST API to open files.
It will work with the relative paths only when the IDE is already running and the project is open: http://localhost:63342/api/file/relative/to/module/root/path/to/file.kt.
With the JetBrains Toolbox App installed one will be able to use jetbrains:// protocol for navigation, it's work in progress and should be available in 2019.2.
See JBProtocolNavigateCommand.kt for the reference:
// handles URLs of the following types:
// jetbrains://idea/navigate/reference?project=IDEA
// [&reference[X]=com.intellij.navigation.JBProtocolNavigateCommand[.perform][#perform]]+
// [&path[X]=com/intellij/openapi/project/impl/JBProtocolNavigateCommand.kt[:23[:1]]]+
// [&selection[X]=25:5-26:6]+
Sample URL:
jetbrains://idea/navigate/reference?project=IDEA&fqn=com.intellij.openapi.application.JetBrainsProtocolHandler#getParameters
Toolbox URL matches regexp:
"${JetBrainsProtocolHandler.PROTOCOL}([\\w\\-]+)/navigate/reference\\?project=(?<project>[\\w]+)(&fqn[\\d]*=(?<fqn>[\\w.\\-#]+))*(&path[\\d]*=(?<path>[\\w-_/\\\\.]+)(:(?<location1>[\\d]+))?(:(?<location2>[\\d]+))?)*(&selection[\\d]*=(?<line1>[\\d]+):(?<column1>[\\d]+)-(?<line2>[\\d]+):(?<column2>[\\d]+))*"
There will be also UI for copying TBX protocol URLs directly from the editor similar to the Copy Reference action in the context menu. The same will work for IDE settings navigation.
As an update to #CrazyCoder's answer
This works* on Mac currently. (unable to test on anything else personally)
* There are some issues:
There is no context menu option for generating this link from clicking on a line of code
The keybinding (see below) generates the incorrect path, and it needs to be modified manually by either changing the sources root temporarily, or typing the missing path parts by hand.
There is a keybinding you can use to generate the url, under Preferences > Keymap > Copy Path/Reference > Toolbox URL. Note that the cursor location when using the keybinding matters. From what I can tell, if the cursor is at the beginning or end of a line, it generates a url with &path=..., else it generates with &fqn=.... The fqn option will often link to the wrong area of the code, especially when interfaces, libraries, auto-wiring, or anything not a direct vanilla class/object/function is attempted to link to.
I have filed an issue with more details on the broken path generated by the keybinding: https://youtrack.jetbrains.com/issue/IDEA-290640
I am using geo-location for a site running locally on my machine using HTTP on Chrome. However this does not work as I am running on HTTP as opposed to HTTPS.
On the console it says:
getCurrentPosition() and watchPosition() no longer work on insecure origins.
To use this feature, you should consider switching your application to a
secure origin, such as HTTPS. See https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins
for more details.
Accoriding to Deprecating Powerful Features on Insecure Origins its says to start chrome using --unsafely-treat-insecure-origin-as-secure="http://example.com" flag. The command I ran was similar to:
chrome.exe --unsafely-treat-insecure-origin-as-secure="http://hello.app"
However, the same error message still appears.
How can I fix this issue.
None of the solutions worked for me.
I achieved this by following steps.
Type chrome://flags/#unsafely-treat-insecure-origin-as-secure in the address bar.
Add the origin which you need to treat as secure as shown in the below image.
Relaunch chrome.
You must have missed some steps. Try to follow this
Go to File Explorer then paste this to address bar >> C:\Program Files (x86)\Google\Chrome\Application (or just go to where you can find your chrome.exe)
Right click chrome.exe > send to > Desktop (Create Shortcut)
Go to your desktop then find the chrome shortcut you've created.
Rename it to ChromeForTesting (this step is optional)
Right click the shortcut, then Click Properties
At the "Target", paste the following at the end of the link
--user-data-dir=/tmp/foo --unsafely-treat-insecure-origin-as-secure=http://example.com
so Target should look somewhat similar to this
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=/tmp/foo --unsafely-treat-insecure-origin-as-secure=http://example.com
Click Ok..
During testing close all of your opened google chrome browser.
Then double click ChromeForTesting shortcut (the one you've created), when a prompt appears, just click ok..
EDIT: If the steps above does not work for you, you might be using Chrome V63, update it to V64 above cause this flag is messed up in V63.
P.S. If it's still not working follow these extra steps
At your drive C, create a folder and name it "ChromeTempFiles".
Then in your --user-data-dir= you change the value into "C:\ChromeTempFiles"
Add these to your target as well
--allow-running-insecure-content --reduce-security-for-testing
so your target should look like this now
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=C:\ChromeTempFiles --unsafely-treat-insecure-origin-as-secure=http://example.com --allow-running-insecure-content --reduce-security-for-testing
You should also use a temproary fresh profile for that session. something like this:
chrome.exe --user-data-dir=/test/only/profile/dir --unsafely-treat-insecure-origin-as-secure="http://example.com"
Just an update to this for Chrome 70. This works perfectly
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=C:\ChromeTempFiles --allow-running-insecure-content
Now does anybody know if there is an equivalent for firefox?
For Chromium 44 use
--unsafety-treat-insecure-origin-as-secure=http://192.168.0.101:3000
instead
--unsafely-treat-insecure-origin-as-secure=http://192.168.0.101:3000
See that bug
In Google Chrome, you simply type into the address bar, "chrome://flags", and search for, "--unsafely-treat-insecure-origin-as-secure", enable that flag, and enter into the field below (multiples may be entered separated by a comma) the domain you wish to treat as secure. This may or may not compromise your security, but I would assume not as getCurrentPosition() and watchPosition() are somewhat recently deprecated features. this works for publicly served domains, as well.
With Chrome 79 this setting doesn't work no matter what.
What I ended up doing was to configure the domain on a VPS to show some test webpage and then generate a valid certificate for it using Let's Encrypt's certbot.
Then I copied that certificate to my machine and it's now valid.
After running code I generate a link to redirect me to a directory found on the local server to which I have full access.
When clicking the link after run i get error message in the console : "not allowed to load local resource", but if I copy the same link and put it in a new browser tab, it functions correctly and redirects me to the specified directory. This issue is not specific to browser, the problem appears in all types of browsers.
Example for link using File Protocol :
Link
When you put a URL directly in the address bar then you, the user, are explicitly requesting it and (in theory) know what you are doing.
When you click on a link, the browser doesn't trust that the author of the page isn't trying to trick you, so additional security restrictions are applied.
I'm attempting to load a page that does a call to ADFS for authentication purposes. On the page load, there is a redirect and then popup to enter credentials.
HTTPS must be used.
Chrome must be used as the testing browser.
So, when loading the page everything is working fine, but I'm forced to manually enter credentials when running the test. After inputting the credentials everything is fine, but is there a way to leverage Watir to input this for me? I've tried popping the username:password into the link already with no success, and since I really need to use Chrome the Firefox plugins are moot.
require 'watir-webdriver'
b = Watir::Browser.new :chrome
b.goto 'https://internalUAT.clientwebsite.com/'
b.link(:text => 'HR Dashboard').click
I'm not allowed to post images due to reputation constraints, but please visit
https://i.imgur.com/ExVt8fp.png
for a screenshot.
When you try passing credentials with the https://user:pass#foo.com technique, do you have any unusual characters in the username or password? (Maybe you have a DOMAIN\username domain prefix?)
If so you might want to make sure any such characters in the credential string are properly escaped.
If that's not the problem, and there's no other way to disable the auth prompt for your tests, then your best bet (IMO) is to write a separate script (or thread) that uses RAutomation (or some other UI automation library of your choosing) to enter your credentials and click the Log In button.
See https://github.com/jarmo/RAutomation
The test cases in the following file contain examples of using RAutomation's send_keys method, which could prove useful:
https://github.com/jarmo/RAutomation/blob/master/spec/window_spec.rb
For the record, it looks like RAutomation may have been used by watir-classic for dialog handling:
https://github.com/watir/watir-classic/blob/master/lib/watir-classic/modal_dialog.rb
http://www.rubydoc.info/github/watir/watir-classic/Watir/ModalDialog
I have finished an extension for my company and I want to put it on the company wiki so that in order to get it on everyone's machine all I have to do is go around and click the link.
First, I HAVE READ all the documentation from http://developer.chrome.com/extensions/hosting.html about hosting and autoupdating and all that. Part of it confuses me and I can't find any more information about this:
Google Chrome considers a file to be installable if either of the following is true:
The file has the content type application/x-chrome-extension
The file suffix is .crx and both of the following are true:
The file is not served with the HTTP header X-Content-Type-Options: nosniff
The file is served with one of the following content types:
empty string
"text/plain"
"application/octet-stream"
"unknown/unknown"
"application/unknown"
"*/*"
This looks like it wants a MIME style setup? but I have never done anything with this. I have the ability to change what I want to the Locally hosted Wiki, all I need is to understand what need to change to make the link installable. I will keep looking for examples.
Note: The reason it is not going on the app store is that there is really no reason to. It is branded for our company, and communication with our specific servers is hard-coded into it.
In version 21 (or so), Chrome disabled the ability to do a simple link-click install of off-store extensions. There is a discussion of the change in this bug report:
You are no longer supposed to be able to install extensions off-store in Chrome... In order to install off-store extensions, the user must download them to a directory and drag them onto chrome://extensions/.
There is, therefore, no longer any way to install an extension simply by clicking a link, except by hosting it in the Web Store. You will need to download the file and then drop it into chrome://extensions.
The documentation you reference looks out of date (that's Google's fault, not yours). It definitely fails to mention the new drag-and-drop requirement. It also talks about the file's "content type" and the X-Content-Type-Options HTTP header required to make the CRX installable; however, when you install an extension by dropping it into chrome://extensions, I doubt very much that Chrome remembers what HTTP headers were set when you first downloaded the file.
EDIT: You can also use the --enable-easy-off-store-extension-install command line flag to restore the old instalation behavior.
You can do an "inline install" of an app hosted on the web store. The new changes are forcing people to move our extensions to the web store, but the inline installation should allow your users to not need to leave your page to install.