How to define ActiveXObject in selenium.geEval method? - javascript

i'm using selenium rc for automation i used selenium.GetEval(" var fso = new ActiveXObject('Scripting.FileSystemObject')"); but it shows activex not defined error during run time..

selenium.GetEval(" var fso = new ActiveXObject('Scripting.FileSystemObject')"); it will work only IE not in FireFox.

Related

C# Selenium access browser log

Is there a way of capturing browser logs in c# using selenium.
I am looking to capture any JS errors that appear on a particular page. Preferable on Chrome or Firefox.
I have previously done this in Python but can this be done in C#?
To set-up and retrieve the log entries with Selenium / Chrome / C# :
ChromeOptions options = new ChromeOptions();
options.SetLoggingPreference(LogType.Browser, LogLevel.Warning);
var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://stackoverflow.com");
var entries = driver.Manage().Logs.GetLog(LogType.Browser);
foreach (var entry in entries) {
Console.WriteLine(entry.ToString());
}
And with Firefox:
FirefoxOptions options = new FirefoxOptions();
options.SetLoggingPreference(LogType.Browser, LogLevel.Warning);
var driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("http://stackoverflow.com");
var entries = driver.Manage().Logs.GetLog(LogType.Browser);
foreach (var entry in entries) {
Console.WriteLine(entry.ToString());
}
This library can help you with that: JSErrorCollector.
When you're using it you just have to write one line to get all the errors listed:
List<JavaScriptError> jsErrors = JavaScriptError.ReadErrors(driver);

Can I create a folder using Javascript program

Can I create a folder using Java script program like
var fso, fldr;
fso = new ActiveXObject("Scripting.FileSystemObject");
fldr = fso.CreateFolder("C:\\MyTest");
ActiveXObject is only available within Internet Explorer, also the correct permissions must be set before this is possible.
More info:
http://www.ezineasp.net/post/Javascript-FSO-CreateFolder-Method.aspx
Yes you can create, however it will only run IE browser and you need to perform IE - setting too.
var folder = "C:\\testing";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FolderExists(folder)) {
fso.CreateFolder(folder);
}
fso=null;
It's not possible with other Browsers! And that's good!

ActiveXObject FileSystemObject not releasing in Javascript

I have a Javascript function that saves JSON data locally, using an ActiveXObject in IE9. It links into FileSystemObject or FSO scripting for file access.
If this Javascript function is run more than once, I get an error in IE debugger: "SCRIPT70: Permission denied" pointing to ts = savefile.OpenAsTextStream(2);
Why will it run just fine the first time, but not after that? My best guess is that something's not being released properly, although I can find no information on MSDN (or here).
Here's the code:
function SaveMyJSON() {
var ts;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var savefilepath = "C:\\MyFolder\\saveFile.json"
var savefile = fso.GetFile(savefilepath);
// open for writing only, value 2, overwriting the previous
// contents of the file
ts = savefile.OpenAsTextStream(2);
var myTestJson = {"id1" : "one", "id2" : "two"};
// copy to json
ts.WriteLine(myTestJson);
ts.Close;
}
The Close method needs empty parenthesis after it, like so:
ts.Close();
Ref here for more info.

ReferenceError: not defined with activeX

what does it mean to get this error:
ReferenceError: ActiveXObject is not defined
var fso = new ActiveXObject("Scripting.FileSystemObject");
here is my code:
var fso = new ActiveXObject("Scripting.FileSystemObject");
varFileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
newObject.write(XML.innerHTML);
newFileObject.close();
thanks in advance..
The problem is the security setting of your browser is blocking it.
If you try IE6 the code should work. You have to use a dead browser because the new browsers block it from working as part of a killbit fix that Microsoft did to fix a security issue.

Javascript: Save file with ActiveXobject

I am working on an Asp .net project and i have a textarea in an aspx page, and i am trying to save textarea contents on a file on the server by clicking a button with the following code:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\temp1\\testfile.txt", true);
a.WriteLine(saveData);
a.Close();
The issue is if the file does not exists , then it creates it. But if it exists it dodes not overwrite it. Any help pls ? (I have to mention that Localy runing the application with visual studio then it rewrites it, but it doesnt works on the published version )
Use rather OpenTextFile() than CreateTextFile(). It also creates non-existing file if needed.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("c:\\temp1\\testfile.txt",2, true);
a.WriteLine(saveData);
a.Close();

Categories

Resources