I've got a crunchy scraping problem in my hands with a lot of javascript that creates session-dependent cookies and I am trying to bypass this question using selenium. I'm using the python driver (python-selenium, version 2.2.0-1 on debian). Without the Remote Driver obtained from selenium-server-standalone-2.39.0.jar the browser was starting but not working (it reported some profile issues). Using the Remote Driver everything is fine except that set_preference is not working (I need to define a browser_profile in order to be able to automatically save some files):
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/tmp')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
#browser = webdriver.Firefox()
browser = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX, browser_profile=profile)
In this way not only the dialog with the save/open choice is opened but examining about:config I do not find the confs to have been set.
On this debian I've got Iceweasel 24.2.0 but I've also tried on a ubuntu with plain firefox with no luck.
Any idea about what could be my problem?
I realize this is a bit late, but I found what I believe is the actual answer to this question.
Turns out that
profile.set_preference("browser.download.manager.showWhenStarting",False)
attempts to set a preference that FF doesn't recognize. If you look in about:config at a normal profile, that setting isn't there. At least not as of FF 35. Maybe it was sometime in the past, but no more.
Anyhow, that is apparently enough to make the revised profile invalid, causing FF to reject the whole thing (or possibly causes the Selenium library to crash when passing the profile to FF) at:
browser = webdriver.Remote(..., browser_profile=profile)
Related issue:
https://code.google.com/p/selenium/issues/detail?id=7017
I found that removing that call to set_preference setting allowed the modified profile to take effect.
My tentative conclusion is that the modified profile must have only modifications that FF understands.
Could you just make the settings you need and permanently save the profile? You could then load this profile without the need for set_preference.
edit:
Also, see Python - Remote Webdriver with Extension installed in it
Your solution for this case here
This cause of the profile has not be adopted. We need to notify the firefox to update the new profile.
Related
Hope everyone is doing okay đ
Currently Iâm trying to get info from a page where I have to sign in and then complete a Captcha (selecting different pictures) in order to proceed. The thing is that when I enter the page from my default browser (like manually clicking chrome) I donât need to sign in and complete the captcha, because I am already signed in (I think because of the cookies?).
Every time I run selenium it opens a âblankâ Chrome, is it possible to open a browser with all my data already loaded in order to skip the captcha?
I have tried different solutions explained here but with no success How to save and load cookies using Python + Selenium WebDriver
Thank you very much!
Yes there is a way: You can load your Chromebrowser with the chrome-profile saved on your computer. To do this you have to use webdriver.Chromeoptions().
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\YourUser\AppData\Local\Google\Chrome\User Data\')
PATH = "/Users/YourUser/Desktop/chromedriver"
driver = webdriver.Chrome(PATH, options=options)
In your chrome-user, every cookie and stuff is saved and you no longer have a clean browser. Remember: There are still websites which can detect that your using selenium, but there are only a few...
After running my Selenium/Python program, browser opened with below message:
This is the initial start page for the WebDriver server
I have done below steps to resolve this:
In IE Options -> Security tab, Enable Protected Mode check box is ticked OFF in all zones: Internet,
Local Intranet, Trusted sites and Restricted sites. Also, in Advanced tab -> Security, ticked OFF the
check box: "Enable Enhanced Protected Mode" (Also, I tried with enabling this Protected Mode in all
zones and in Advanced tab too).
My IEdriver (version 3.1.4) and Selenium web driver (version 3.1.4) are compatible (both are on same
version)
I tried above two, still I am getting the same message.
I have added below content to ignore Protected mode:
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
driver = webdriver.Ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe',capabilities=caps)
Still, I am getting the same message after adding above code.
Any ideas? Please help.
This is as per design. When IEDriverServer.exe opens a new a new Browsing Context i.e. Internet Explorer browsing session it navigates first to this page.
Browser Snapshot
Once you initialize the browser through the line:
driver = webdriver.Ie(executable_path='C:/Selenium/Drivers/IEDriverServer.exe',capabilities=caps)
next you can invoke the get() command to access any url. As an example:
driver.get('https://www.google.com/')
Additional Consideration
Additionally you need to:
Upgrade Selenium to current levels Version 3.141.59.
Upgrade IEDriverServer to latest IEDriverServer v3.150.1 level.
Note: As per best practices as Selenium Client and InternetExplorerDriver are released in sync and you must try to use both the binaries from the same major release.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
When I try to use Cookies file (sqlite fomatted) on Linux (Ubuntu) and Windows I fall into troubles with decryption of 'encrypted_value'. Is there any chance to make Cookies file compatible with two systems?
Basically selenium driver use Cookies file for various purpouses, and everything works on Linux. Sometimes my action is needed, so I want to have this Cookies file on my desktop which works on Windows, but when I download it directly and copy-paste it to my profile directory, my chromedriver logs error:
[4708:4884:0604/082853.607:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
I assume that there is some problem with 'encrypted_value' column decryption but I am unable to work-around this issue.
I use selenium for python this is snippet where I create options for my webdriver:
def create_options_for_webdriver(session_directory):
print('Creating options for webdriver!')
options = Options()
options.add_argument("user-data-dir=my_userdir")
options.add_argument("user-agent=my_useragent")
options.add_argument('--disable-background-networking ')
options.add_argument('--disable-client-side-phishing-detection')
options.add_argument('--disable-default-apps')
options.add_argument('--disable-hang-monitor')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-prompt-on-repost')
options.add_argument('--disable-sync')
options.add_argument('--disable-web-resources')
options.add_argument('--enable-automation')
options.add_argument('--enable-blink-features=ShadowDOMV0')
options.add_argument('--force-fieldtrials=SiteIsolationExtensions/Control')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--no-first-run')
options.add_argument('--password-store=basic')
options.add_argument('--use-mock-keychain')
return options
before option creating I create minimal directory structure which looks like my_userdir/Default/, and I download Cookies file to Default folder.
... when I download it directly and copy-paste it to my profile directory, my chromedriver logs error:
[... ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
It looks like it is not possible. Or maybe not possible they way you are trying to do it. It takes extra effort.
The question Decrypting Chrome's cookies on windows has a link to os_crypt_win.cc. os_crypt_win.cc uses DPAPI, which is the old WinCrypt gear. DPAPI ties encryption to a user's Windows login. DPAPI also places a MAC on the encrypted data. I believe the MAC is the reason for the message you are seeing: "The parameter is incorrect". DPAPI sees the MAC over the encrypted data is wrong, and it gives you the generic error message.
So if you truly want to use the Linux cookie on Windows, you will need to decrypt it using the Linux spec, and then re-encrypt it using the Windows spec.
If you are going to pursue it, then you may want to visit this BlackHat talk: Reversing dpapi and stealing windows secrets offline. It will allow you to encrypt the user's data on Linux for Windows.
Coming back with update!
It appears that, as #jww mentioned process is more complicated, but just a little :)
In order to make Cookies fully compatible with any OS some special treatment must be applied.
In my case I used pickle library to create compatible file. To achieve it, things needs to be done as follow:
from selenium.webdriver import Chrome
import pickle
driver = Chrome()
####here you do some job which generate cookies like FB login or whatever
input("Press any key to close session") #you cant simply close browser, in order to make it work browser have to be closed in console so the rest of script will execute
pickle.dump(driver.get_cookies(), open('cookies.pkl',"wb"))
driver.quit()
print("Session closed!")
This will create cookies.pkl file which can be accessed under any OS like that:
import pickle
from selenium import Chrome
driver = Chrome()
for cookie in pickle.load(open("cookies.pkl"."rb")):
driver.add_cookie(cookie)
### anything you want to execute
As I mentioned this kind of cookies file will work under any OS, sadly it forced me to use selenium, but better this than nothing :)
I have an automated test which fills the User + Password fields and click a certain button to Login.
During the development session I managed to run this automation tens of times without any problem. Suddenly today I found out that the response to the automated test has changed and now I can't Login. I can say that the WEB under test didn't change. I can almost tell for sure that the FireFox that is run by the automated test has updated without my control (the browser that the automated test runs has an up-to-date version 54 while the browser that I run has a version 52).
I have tried to configure the Version 54 so that he won't pop-up the message (through the about:config) but my settings are not saved.
First of all I would like to know how can I manage to get rid of the pop-up message ?
Second thing I would like to know how can I prevent the updates of the browser version ?
Could it be that the geckodriver has its own FireFox settings and Version ?
Firstly, you can configure FirefoxProfile to accept untrusted connections, as shown below:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
driver = webdriver.Firefox(firefox_profile=profile)
This answer contains configuration details about other browsers as well.
Secondly, in order to disable automatic updates for Firefox browser, you can follow following steps:
Launch Firefox and go to 'Tools->Options->Advanced'.
Click on 'Updates' tab.
Click on 'Never Check for updates' option button under 'Firefox updates' section.
Restart Firefox.
Let me know, if it resolves your issue.
You need to set acceptInsecureCerts to true in your capabilities.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.MARIONETTE, true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
WebDriver webDriver = new FirefoxDriver(capabilities);
Edit: Sorry about the java code. The thing is you need set that capability.
I am trying to force selenium to ignore SSL errors, but haven't been able to figure it out. I have seen acceptSslCerts capability, but it does not seem to have any effect when using firefox
For your scenario, you can try something similar to this. It worked well for me on Firefox browser.
Create new firefox profile by following below step and accept SSL certificates there.
Close all your firefox windows
In the Run dialog box, type in: âfirefox.exe -p' and then Click OK.
Click âCreate Profileâ
Create a name for your new profile(say Selenium)
Click âChoose Folderâ
Pick something easy to find â like âC:\NewFirefoxProfileâ
Click Finish
Now after selecting newly created profile, start Firefox. Open the specific url you were getting 'Secure Connection Issue', accept SSL certificates for this profile
Now use the newly created firefox profile to run your selenium test. Modify below code as per your requirement.
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
profile.assume_untrusted_cert_issuer=True
driver = webdriver.Firefox(firefox_profile='C:/NewFirefoxProfile)
driver.get('https://cacert.org/')