I do not have privileges to change IE settings locally. I wrote a Java Code to change the capabilities of IEDriver using :
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
I want to do the same thing while using the selenium webdriver in Robot Framework. I want to do something like this. But I do not know the right way to do it.
*** Keywords ***
Test Browser
${options}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER sys,selenium.webdriver
Call Method ${options} add_argument INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:True
Create WebDriver Internet Explorer ie_options=${options}
Open Browser To Login Page
Open Browser ${LOGIN URL} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Thanks a lot!
In the Selenium documentation for DesiredCapabilities, the configurable properties are listed. The required property is ignoreProtectedModeSettings which must be set to True
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER sys, selenium.webdriver
Set To Dictionary ${dc} ignoreProtectedModeSettings ${True}
Open Browser www.google.com ie desired_capabilitie=${dc}
${s2l}= Get Library Instance Selenium2Library
Log Dictionary ${s2l._current_browser().capabilities} # actual capabilities
For anyone that came here looking for a solution to this problem within Robot Framewor:
Set Chrome Desired Capabilities
[Documentation] Create the desired capabilities object with which to instantiate the Chrome browser.
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.CHROME sys, selenium.webdriver
${experimental_options} Create Dictionary useAutomationExtension ${False}
Set To Dictionary ${dc} chromeOptions ${experimental_options}
Set Global Variable ${DESIRED_CAPABILITIES} ${dc}
As Pavol Travnik mentioned, David's answer no longer works. At some point the ignoreProtectedModeSettings key got placed inside the se:ieOptions dictionary within the capabilities dictionary. Here is code that will work with newer versions of the IEDriverServer:
${ie_dc} = Evaluate
... sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER
... sys, selenium.webdriver
${ieOptions} = Create Dictionary ignoreProtectedModeSettings=${True}
Set To Dictionary ${ie_dc} se:ieOptions ${ieOptions}
Open Browser ${url} ie desired_capabilities=${ie_dc}
You can see this if you debug Selenium's Python library, specifically webdriver/remote/webdriver.py and look at the response in start_session.
Related
I am using selenoid for remote browser testing in ruby.
In that I am using 'selenium-webdriver', 'capybara', 'rspec' for automation. And I am using attach_file method for uploading file to browser
I want to upload file on Firefox and Chrome browser but it raises error on both;
In chrome
Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/***8d32e045e3***/se/file
In firefox
unexpected token at 'HTTP method not allowed'
So After searching I found the solution for chrome which is to set w3c option false in caps['goog:chromeOptions'] > caps['goog:chromeOptions'] = {w3c: false}
So now chrome is using OSS bridge for handshaking but I don't know how to do it in Firefox. Similar solution is not available for Firefox.
My browser capabilities are following:
if ENV['BROWSER'] == 'firefox'
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browserName'] = 'firefox'
# caps['moz:firefoxOptions'] = {w3c: false} ## It is not working
else
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserName"] = "chrome"
caps["version"] = "81.0"
caps['goog:chromeOptions'] = {w3c: false}
end
caps["enableVNC"] = true
caps["screenResolution"] = "1280x800"
caps['sessionTimeout'] = '15m'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :remote,
:desired_capabilities => caps,
:url => ENV["REMOTE_URL"] || "http://*.*.*.*:4444/wd/hub"
)
end
Capybara.configure do |config|
config.default_driver = :selenium
end
I have found the problem. There is bug in selenium server which run on java so I have to change my selenium-webdriver gem version 3.142.7 and monkey-patch.
You can find more information here about the bug and resolution.
For now I have to change my gem and monkey patch the selenium-webdriver-3.142.7\lib\selenium\webdriver\remote\w3c\commands.rb file. check for below line which is on line no 150.
upload_file: [:post, 'session/:session_id/se/file']
and update it to
upload_file: [:post, 'session/:session_id/file']
i had a similar issue with rails 7. the issue is connected with the w3c standard. the core problem is that the webdriver for chrome uses a non-w3c standard url for handling file uploads. when uploading a file, the webdriver uses the /se/file url path to upload. this path is only supported by the selenium server. subsequently, the docker image provided by selenium works fine. yet, if we use chromedriver, the upload fails. more info.
we can solve this, by forcing the webdriver to use the standard-compliant url by overriding the :upload_file key in Selenium::WebDriver::Remote::Bridge::COMMANDS. since, the initialization of this the COMMANDS constant does not happen when the module is loaded, we can override the attach_file method to make sure the constant is set correctly. here the hacky code:
module Capybara::Node::Actions
alias_method :original_attach_file, :attach_file
def attach_file(*args, **kwargs)
implement_hacky_fix_for_file_uploads_with_chromedriver
original_attach_file(*args, **kwargs)
end
def implement_hacky_fix_for_file_uploads_with_chromedriver
return if #hacky_fix_implemented
original_verbose, $VERBOSE = $VERBOSE, nil # ignore warnings
cmds = Selenium::WebDriver::Remote::Bridge::COMMANDS.dup
cmds[:upload_file] = [:post, "session/:session_id/file"]
Selenium::WebDriver::Remote::Bridge.const_set(:COMMANDS, cmds)
$VERBOSE = original_verbose
#hacky_fix_implemented = true
end
end
In Firefox images we support /session/<id>/file API by adding Selenoid binary which emulates this API instead of Geckodriver (which does not implement it).
I try to disable popup blocking in Robot Framework for Firefox in different ways: by setting preference dom.disable_beforeunload=False, setting capabilities and profile. It does not work. Pop up confirmation windows are not shown. See Open Firefox browser keyword:
*** Keywords ***
Open Firefox browser
${options}= Evaluate sys.modules['selenium.webdriver'].FirefoxOptions() sys
Call Method ${options} set_preference dom.disable_beforeunload False
Call Method ${options} set_capability unhandledPromptBehavior ignore
Call Method ${options} set_capability unexpectedAlertBehaviour ignore
${profile}= Evaluate sys.modules['selenium.webdriver'].FirefoxProfile() sys
Call Method ${profile} set_preference dom.disable_beforeunload False
${desired_capabilities}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.FIREFOX sys
Set To Dictionary ${desired_capabilities} unhandledPromptBehavior ignore
Set To Dictionary ${desired_capabilities} unexpectedAlertBehaviour ignore
Open Browser ${LOGIN_URL} Firefox options=${options} ff_profile_dir=${profile} desired_capabilities=${desired_capabilities}
For Chrome there is no such a problem. Everything works by adding the argument --disable-popup-blocking.
Open Chrome browser
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${options} add_argument --disable-popup-blocking
Call Method ${options} add_argument --ignore-certificate-errors
Open Browser ${LOGIN_URL} Chrome options=${options}
Based off the answer here I am trying to get Chrome to run headless in my script.
The snippet of code below is inside of a function called login() that logs into our ERP system:
if headless == True:
options = Options()
options.headless = True
#Load webdriver
driver = webdriver.Chrome(options=options, executable_path=r'C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
if headless == False:
driver = webdriver.Chrome('C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
window_before_login = driver.window_handles[0]
### Removed Code Block that fills out login form and clicks 'Login' button ###
# Switch to new window ERP (PLEX) launches and close original blank one no longer needed.
window_before_login = driver.window_handles[0]
window_title = driver.title
driver.switch_to.window(window_before_login)
driver.close()
driver.switch_to.window(driver.window_handles[0])
When I call my function like so:
login(headless=False)
It throws no errors and my entire script executes just fine.
When I call my function like this:
def login(headless=True)
I get the following errors:
DevTools listening on ws://127.0.0.1:57567/devtools/browser/69f9e357-dccf-4e38-8d6b-78030462379a
[0204/072436.206:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/modules/systemadministration/login/index.aspx? (6)
[0204/072437.699:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/Modules/SystemAdministration/Login/Index.aspx (6)
[0204/072437.722:INFO:CONSOLE(1)] "Scripts may close only the windows that were opened by it.", source: (1)
[0204/072441.162:INFO:CONSOLE(751)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source: https://test.plexonline.com/Modules/scripts/ajax.js (751)
I am using Chrome Version 79.0.3945.130 (Official Build) (64-bit), Selenium 3.141.0, and Python 3.7.4.
Any ideas what I am doing wrong? Thank you!
I am trying to hide the CMD window that appears when launching PhantomJS with python:
from selenium import webdriver
browser = webdriver.PhantomJS()
There appears to be a solution when working with C#, however, I was not able to find anything similar for python. Since the feature for C# was added back in 2014, I assume something similar should exist for python too.
I'm using latest PhantomJS and Python 3.6.2.
This is how it looks like:
For me,
The below code works fine.
driver = webdriver.PhantomJS(
service_args=service_args,
desired_capabilities=caps,
executable_path='phantomjs.exe',
service_log_path=None
)
Here you have to add service_log_path=None for no log file that's why the console window will get hidden.
Still Not solved then
replace code from
(C:\Users\YOUR_USER_NAME\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\selenium\webdriver\common\service.py) file
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)
to
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)
I am having an issue with entering text into the address bar nothing happens and I get the error
selenium.common.exceptions.WebDriverException: Message: Can't load the
profile. Profile Dir:
/var/folders/8_/f48lnzrs7r59_h2yb3dkfbh40000gn/T/tmpsGffLD If you
specified a log_file in the FirefoxBinary constructor, check it for
details.
I am able to open the browser but when I uncomment the code browser.get('http://www.google.com') nothing happens and I get the error listed above. I am using Firefox 48, Python 2.7.10 and selenium-2.53.6-py2.7.egg
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')
Change that line to
browser.url('http://www.google.com')
OR
browser.open('http://www.google.com')