I'm using Selenium WebDriverJS (via node) to do some automated testing. I have a test I'm trying to write to work on multiple browsers, and it works fine on Chrome and Firefox, but in IE (version 11, 32-bit), I keep having the consistent problem where I can't switch to other windows besides the main one.
Basically, as part of the test I'll have it click a button that opens up a link in a new window, then I attempt to switch to that window and continue. Getting all the window handles and then using switchTo() to switch has worked fine in the other browsers, but not IE. Using the same method gets me the error:
UnknownError: null value in entry: name=null
...
==== async task ====
WebDriver.switchTo().window(undefined)
So I ran:
driver.getAllWindowHandles().then(function (handles) {
console.log(handles.length)
});
to see if the windows were appearing. And every time, the result has been 1, being only the main window. I can see the new windows that have been opened, but webdriver can't for whatever reason. Is there anything more I need to do to get these windows to be visible to the driver? Any sort of workaround?
I know that IE requires some settings to work properly with Selenium. My protected mode settings are fine, and I've done the FEATURE_BFCACHE key in the registry. It just seems to be unable to find any new windows.
Using IE 11 with the 32-bit driver, and Windows 7 64-bit. Again, my language is javascript. Let me know if there is more info you need to answer.
Related
I am listening to a server event via a javascript function on my HTML file, which outputs the server answer in the console tab. Since I need to pass this answer to a delphi application, I made the server answer "visible" via a div container. This works fine on Firefox, but on IE the output is not shown. I have then tried to utilize the value of a textarea, which also works on Firefox but not on IE.
I really wonder why it is so hard to get a console output visible on IE?
document.getElementById('my_div_container').innerHTML = JSON.stringify(my_data_I_want_to_see, null, 4);
document.getElementById('my_textarea').value = JSON.stringify(my_data_I_want_to_see, null, 4);
The above lines show a result on Firefox, but on IE there is no output at all. How can I get my data visible on IE?
I found the root cause why IE did not show any console output. I just found out, that the addEventListener() method I was using is not supported in Internet Explorer 8 and earlier versions.
I am very sorry for any confusion.
If you are using TWebBrowser component in Delphi for displaying the webpage do note that by default it running in Internet Explorer 7 compatibility mode.
In order to avoid this you need to opt your program into browser emulation feature
How to have Delphi TWebbrowser component running in IE9 mode?
Don't forget to check MSDN documentation for proper registry value to enable emulation of most modern IE versions.
I'm using Firefox Quantum (64.0) and the JS command new WebSocket() returns a different object from the specification:
MDN Websocket
HTML Standard
The missing property that is affecting my appllication is the .close() function, but there is another differences.
You can see in the image bellow that the returned object has a .websocket porperty that contains all the missing ones.
websocket object
Am I doing something wrong? With older versions of Firefox (before Quantum, like 43) or with chrome it works fine.
If it is a problem with firefox, how can I report it?
EDIT:
Adding some code example:
var exampleSocket = new WebSocket("wss://echo.websocket.org");
exampleSocket.close() // Throw "exampleSocket.close is not a function" in Firefox Quantum, works on chrome
exampleSocket.websocket.close() // Works on Firefox, Throw on chrome.
This exampleSocket.websocket is not in the documentation.
Edit2:
I tested in other machines that have the firefox versions 60, 61, 63 and 64 and the problem only happened in my machine.
When I removed all plugins from firefox it started to work again.
The problem was the websocketsniff plugin that I had installed.
It even state that the WebSocket object will change:
Inspect websocket frames in Firefox. How to use: 1) Open Developer
Tools 2) Open "Websocket Sniffer" tab
This extension replace native websocket object for custom object. It
is dirty hack, but it is single decision
I am using Chrome headlessly.
I tried setting the --disable-javascript command line argument.
I tried using the experimental options:
$options->setExperimentalOption('prefs', [
'profile.managed_default_content_settings.javascript' => 2//this does not work
//,'profile.default_content_setting_values.javascript' => 2//this does not work, too
]);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
As of this point these two do not work.
How can I disable javascript in Chrome using the Facebook PHP Webdriver ?
Here is a test to check if JavaScript is enabled:
$this->driver->get('https://www.whatismybrowser.com/detect/is-javascript-enabled');
return [
$this->driver->getTitle(),
$this->driver->findElement(WebDriverBy::cssSelector('.detected_result'))->getText()
];
It is simply impossible. Read here http://yizeng.me/2014/01/08/disable-javascript-using-selenium-webdriver/
WARNING: Running without JavaScript is unsupported and will likely break a large portion of the ChromeDriver's functionality. I suspect you will be able to do little more than navigate to a page. This is NOT a supported use case, and we will not be supporting it.
Closing this as WontFix - the ChromeDriver (and every other WebDriver implementation I'm aware of) require JavaScript to function.
It's possible to disable the execution of Javascript by setting one of the these preferences :
"webkit.webprefs.javascript_enabled": false
"profile.content_settings.exceptions.javascript.*.setting": 2
"profile.default_content_setting_values.javascript": 2
"profile.managed_default_content_settings.javascript": 2
But it's currently not supported headlessly since this mode doesn't load the preferences and there's no command switch related to this feature.
Note that disabling JavaScript used to break Selenium since most of commands are atom scripts injected in the page. It's no longer the case. All the commands are able to run. However I noticed that the returned text doesn't include the text from a <noscript> element (text displayed only when JavaScript is disabled). One workaround is to read the innerText property with either execute_script or get_attribute.
As others have pointed, it is still NOT possible to disable JavaScript in Chrome when headless.
However, for future reference, this is how you do it (when you are NOT using the --headless argument):
$options = new ChromeOptions();
$options->setExperimentalOption('prefs', [
'profile.managed_default_content_settings.javascript' => 2,
]);
$result = DesiredCapabilities::chrome();
$result->setCapability(
ChromeOptions::CAPABILITY_W3C,
// There is a bug in php-webdriver, so ->toArray() is needed!
$options->toArray()
);
Although regular headless mode in Chrome prevents disabling JavaScript, there's a newer headless mode without restrictions.
The Chromium developers recently added a 2nd headless mode that functions the same way as normal Chrome.
The NEW way: --headless=chrome
The OLD way: --headless
There's more info on that here: https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c36
This means that you can now disable JavaScript when using the newer headless mode.
So I am writing a shortcut library and for the most part it works, except for the issue I found right off the bat is in Chrome (haven't tested other browsers since I'm on a chrome book) is that when pressing ctrl+n it creates a new browser window. Basically in jist my code checks if the current key selection is defined and if it is preventDefault and run the exec function of that command.
ie.
if(joinedKeys in commands.cmd)
e.preventDefault();
commands.cmd[joinedKeys].exec();
I've even tried just doing this-
document.addEventListener("keydown",function(e){
e.preventDefault();
});
//as well as window.addEvent...
Neither work. Any suggestions as to stop the default action of the browsers?
See https://stackoverflow.com/a/7296303/5298696
In Chrome4, certain control key combinations have been reserved for
browser usage only and can no longer be intercepted by the client side
JavaScript in the web page. These restrictions did not exist in
Chrome3 and are inconsistent with both Firefox3/3.5 and IE7/8 (on
Windows).
I'm using the following code to get contact presence on a web page:
nameCtrl = new ActiveXObject("Name.NameCtrl.1");
if (nameCtrl && nameCtrl.PresenceEnabled) {
presenceEnabled = true;
nameCtrl.OnStatusChange = onPresenceStatusChange;
// ...
}
It works perfectly when I run it in VS but only from a separate Internet Explorer window, doesn't work in the debug IE window started by Visual Studio (so I cannot debug JS code). What happens is that initially nameCtrl.PresenceEnabled is set to true (just after creating ActivexObject) and then is changed to false, I don't get any status updates and all GetStatus calls return 1.
Any ideas how to make it work in Visual Studio?
I'm targeting IE and Lync.
The whole nameCtrl turns out to be very difficult to debug. Some things to check:
If the plugin doesn’t work in IE11, but works if you change the document mode to IE10, it is because IE11 no longer recognizes ActiveXObject as a property of the window object. (see: http://msdn.microsoft.com/en-us/library/ie/dn423948(v=vs.85).aspx).
No javascript errors but nothing seems to be working? For this to work, you may need to go into Internet Explorer’s Internet Options menu and add your domain (or localhost) as a trusted domain.