I am trying to use Selenium WebDriverJS with the iOS browser. Unfortunately this doesn't work as I need it to do.
I've set up the "iWebDriver"-Project like described at the iPhoneDriver wiki page. I've copied the python script and it worked. Even a small nodeJS project worked, but when I tried to run it from the Browser Firefox gives me the following Error message.
Error: Unable to create a new client for this browser. The WebDriver session ID has not been defined.
The Code I'm trying to run:
var driver = new webdriver.Builder().
usingServer('http://localhost:3001/wd/hub').
withCapabilities({'browserName': 'iPhone'}).
build();
driver.get('http://www.google.com');
driver.quit();
I've compiled webdriverjs like discribed at the WebDriverJs wiki page. And yes, webdriver.js is loaded ;)
So I dug in and I think I have a solution. It seems like a hack but for firefox, and the firefox extension that I am making it works perfectly fine so far.
I edited the webdriver.js file's webdriver.Builder.prototype.build as so
webdriver.Builder.prototype.build = function() {
var a;
// if(webdriver.FirefoxDomExecutor.isAvailable()) {
// return a = new webdriver.FirefoxDomExecutor, webdriver.WebDriver.createSession(a, this.getCapabilities())
// }
a = new webdriver.http.CorsClient(this.getServerUrl());
a = new webdriver.http.Executor(a);
// if(this.getSession()) {
// return webdriver.WebDriver.attachToSession(a, this.getSession())
// }
// throw Error("Unable to create a new client for this browser. The WebDriver session ID has not been defined.");
return webdriver.WebDriver.createSession(a, this.getCapabilities());
};
Basically I am forcing it to create a session, not sure why FirefoxDomExecutor was required since it works just fine on firefox and chrome with changes that I made.
Anyway thanks for getting me on the right track, and hopefully this will help others.
It seems like WebDriverJS is not capable of creating a new Session when not running in Node.js.
You have to create a Session manually and provide WebDriverJS with the session-id as the wdsid GET-Parameter (e.g. urltowebdriver.html?wdsid=someID&wdurl=localhost:9000).
Related
I hava a java program with two buttons, one for chrome and one for firefox. I press one of them, and the browser starts at some particualar location on the screen and with smalles size.
i have try running terminal commands, something like this
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Default" --app="data:text/html,<html><body><script>window.moveTo(198,60);window.resizeTo(1167,708);window.location='https://stackoverflow.com';</script></body></html>"
And it works, but only for chrome. I want at least chrome and firefox on both windows and linux.
Searching a little I have come across other solution. Running javascript on java, somethig like:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("window.open('https://stackoverflow.com')");
engine.eval("window.resizeTo(800,600)");
But Im getting compilation errors:
ReferenceError: "window" is not defined in <eval> at line number 1
And I donĀ“t know whats going. Ideas?
For Windows, you can do something like this using Runtime:
Runtime rt = Runtime.getRuntime();
rt.exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe stackoverflow.com");
I believe that you can do something similar for Google Chrome. I took a look to a code I implemented in the past for Chrome and it was a little different, but previous approach should work as well:
Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"cmd", "/c","start chrome http://www.stackoverflow.com"});
If you would like to do it for a Linux based OS, then you can use Runtime as well:
Runtime rt = Runtime.getRuntime();
rt("/usr/bin/firefox -new-window http://www.stackoverflow.com");
I remember I got some references from this page:
https://www.mkyong.com/java/open-browser-in-java-windows-or-linux/
Hope it can help you.
ScriptEngineManager runs the script on server side. window is a client-side object, you can't access it from server.
in another word since you are not executing your script in a browser, the window object is not defined.
You can try this way to open a website on your default browser of the operating system:
Desktop desktop=Desktop.getDesktop();
URI url = new URI("http://somewhere");
desktop.browse(url);
to open a non-default browser in Java you should use Runtime.exec()
for Windows OS try this it worked for me:
String browserPath = "C:/Program Files/Mozilla Firefox/firefox.exe";
String url = "http://somewhere";
try {
String[] b = {browserPath, url};
Runtime.getRuntime().exec(b);
}
catch (Exception exc) {
exc.printStackTrace();
}
for further information on how to use Runtime.exec() on others OS read here
Is there any way to do this through Java or Javascript, given the link as a String? I've been looking but I've only found topics about Android devices, I'm asking for a Windows PC.
I hadn't planned on learning how to write an extension with the proper permissions for Chrome for this, but if that's the only way then so be it.
To run any executable including Chrome in JAVA:
If the path to the application is a system variable:
String location = System.getenv("APPVARIAVLE");
Process process = new ProcessBuilder(location).start();
Or if you want to use the fully qualified path:
Process process = new ProcessBuilder("C:\\location\\MyApp.exe").start();
The JavaDoc for the process builder say that you can add parameters like this:
new ProcessBuilder("myCommand", "myArg1", "myArg2");
The argument for incognito looks like it is: "-incognito" and to open a url just add the url: "example.com".
Which means that you can most likely can add the url and incognito arguments the following way to chrome in the arguments:
Process process = new ProcessBuilder("C:\\YourChrome\\Location\\chrome.exe","-incognito","http://stackoverflow.com").start();
I have a simple test using the selenium-webdriver javascript package that finds a text field by name and enters text. The test runs fine in Firefox and Chrome, but fails in Phantomjs. I also tried finding the element by xpath and id, but it keeps failing in Phantomjs. Has anyone had a similar experience and could point me in the right direction for debugging?
Thanks
I was facing same issue. In my case, problem was that we have self signed certificate on our test server. I found solution here: phantomjs-and-self-signed-certificates
You have to set desired capabilities for your driver:
DesiredCapabilities dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[]{"--web-security=no", "--ignore-ssl-errors=yes"});
dCaps.setJavascriptEnabled(true);
driver = new PhantomJSDriver(dCaps);
To ignore self signed certificates set "--ignore-ssl-errors=yes"
var sPath = ProChild.GetProperty("File Location");
var sMacro = ProChild.GetProperty("Excel Macro To Run");
//would like to modify following code without using activeXObject
if(sMacro != null && sMacro ==""){
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run(sPath);
New code for better understanding
function OpenFile(){
alert ('Work');
//would like to modify ActiveXObject with any other object for cross-browser.
var x = new ActiveXObject("WScript.Shell");
x.run('winword.exe');
}
//Above code works only in IE. But don't want to use activeXObject.
//Is there any possibility to open a word file in Internet Explorer
//without using activexobject. Request for a solution.
I have tried this sometime back but then this is not actually that easy, there is whole set of functionality that comes up with an application like Excel/Word.
Ultimately displaying excel or word on client machine is a mess, I tried and got stuck in executing macros.
There is nothing to my knowledge that would allow word/excel to be given in all the browser, even AcitveX objects wont let you use most of the functionlity.
Try find some other solution if possible, I has to display a PremiumCalculator excel in webpage instead of letting people download the same, I went ahead and created a PremiumCalculator in asp.net, instead of displaying the existing sheet in web browser.
I built a gadget that shows an on-call rotation for a team, and I am trying to integrate their communicator presence into that shedule. I am using the GetStatus method from the NameCtrl object to get user presence. It works fine in IE when I run it. The problem I am having is that the gadget has a runtime error whenever it hits the ActiveX object declaration. I know this because I commented it out and it runs fine. Any suggestions?
var communicatorPresence = getCommunicatorPresence(userName);
function getCommunicatorPresence(userName){
var obj = new ActiveXObject("Name.NameCtrl.1")
var presence = obj.GetStatus(userName,"")
return presence;
}
I debugged the gadget in Visual Studio and put a breakpoint there, and the error was "Automation Server can't create object"
Depending on the machines UAC settings it might be that gadget does not have read/write access the registry.