I am trying to upload file to Safari(8.0.8) using webdriver. Can anyone confirm it is possible or not? I was searching this problem and I cant find clear information.
My test environment:
I run test at my local PC with Win7 and browser start at Selenium Grid which is running on MAC machine (hub + node run at MAC Yosemite 10.10.5)
First, I try to upload direct file on MAC. But it is not working.
Browser.Driver.FindElement(By.Id("inputID")).SendKeys("/Users/administrator/Desktop/file.txt");
Next, I try to use LocalFileDetetor but it also doesn't work:
driver.FileDetector = new LocalFileDetector();
Browser.Driver.FindElement(By.Id("inputID")).SendKeys("c:\\file.txt");
Next, I try to use: WebDriverBackedSelenium:
ISelenium safari = new WebDriverBackedSelenium(webDriver, "http://systemname/");
safari.Start();
safari.AttachFile("xpath=//input[#id='inputID']", "e:\\file2.txt");
But it doesn't work too. Stack trace:
Selenium.SeleniumException : WebDriver exception thrown
----> OpenQA.Selenium.InvalidElementStateException : Element must be user-editable in order to clear it. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'mac.domain.company.com', ip: '192.168.136.67', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=8.0.8, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}]
Session ID: null
It doesn't work because it is Safari or there is problem with grid/safari/remote host or with file path(something with / )?
Looks like it is not supported https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4220
You can upload using OSAScript. Please do the following:
Create .scpt file in mac with below code
activate application "Safari"
tell application "Safari"
tell document 1
do JavaScript "document.getElementsByTagName('label')[0].click()"
delay 2
end tell
end tell
tell application "System Events"
keystroke "G" using {command down, shift down}
delay 2
keystroke "/Users/melamc/Downloads/upload.jpeg"
delay 2
keystroke return
delay 2
keystroke return
delay 2
end tell
trigger this file whenever you required (write a code to run this file programetically
I hope this will help you, try and let me know
I have done a lot of research to accomplish the uploading of file in safari browser on mac and fortunately I came up with the below solution.
Following are the possible prerequisites to match the given solution:
Programming Environment: c#
Automation Environment: Selenium WebDriver, Selenium Grid
Browser: Safari (12)
OS: MAC (High Sierra)
Hub: Windows machine, Node: Mac machine
In the context of the above to upload the file one can implement the following lines of code.
DesiredCapabilities dc = new DesiredCapabilities();
dc.SetCapability(CapabilityType.BrowserName, "safari");
dc.SetCapability(CapabilityType.Version, "12");
Driver = new RemoteWebDriver(new Uri("http://Node_Ip_Address:Port/wd/hub/"), dc);
Below lines of code do the magic, (This also works for Chrome, and Firefox.)
IAllowsFileDetection AllowsDetection = Driver as IAllowsFileDetection;
if (AllowsDetection != null)
{
AllowsDetection.FileDetector = new LocalFileDetector();
}
In java, the equivalent of the above is
Driver.setFileDetector(new LocalFileDetector());
Reference: https://saucelabs.com/blog/selenium-tips-uploading-files-in-remote-webdriver
The code line written for java has not been tested from my end as I am currently working in c#.
Happy Testing.
Related
This might be a repeated question but I could not find any solution. Recently I found a related post Connecting Selenium WebDriver to an existing browser session but people suggested me to ask a new question.
If any one have tried connecting selenium webdriver to existing browser session that was earlier spawned by selenium itself and had success in doing so, please let me know.
I could find couple of suggestions to try on firefox and selenium 2.X version. But those suggestions do not work for selenium 3.X and there are no solutions for chrome browser.
I have tried all suggestions for Selenium 25.3, firefox v 46 and it works. But for Chrome with chrome driver , I am not able to make it work.
Edited:
Here is the code I have tried:
Starting a firefox driver
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/StartFirefoxSession_lib/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
Copied RemoteWebDriver source code and changed capabilities from private to protected.
protected Capabilities capabilities;
Created a new class RemoteDriverEx extending the copied RemoteWebDriver class
Changed the NEW_SESSION command issued by the original driver to GET_CURRENT_URL
Response response = execute(DriverCommand.GET_CURRENT_URL, Collections.EMPTY_MAP);
Then craeted a JUnit test to verify
But I am struck with exception
org.openqa.selenium.WebDriverException: No command or response codec has been defined. Unable to proceed
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'WPANDBW7HYD', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:154)
Full code shared # https://drive.google.com/open?id=0Bz2XxuQQc24KdHVqR3BPaXowUnM
It is possible in selenium all you need is a debugger address of the session you want to connect to. If you are wondering what is debugger address its nothing but the localhost address on which your session is running, it looks like localhost:60003. Now it will be different for each and every case. Below is process with c# code.
Get debugger Address of browser you want to connect later using debug mode as shown in snapshot below. debug driver after browser launch to fetch value
Now keep that browser running and to reconnect the same browser use below code.
ChromeOptions option = new ChromeOptions();
option.DebuggerAddress="localhost:60422";// we need to add this chrome option to connect the required session
driver = new ChromeDriver(option);
driver.Navigate().GoToUrl("https://www.google.com/");
Hope this helps!! let me know in comments if any clarification is required.
I managed to find a solution for Firefox in a hack way that works local:
First, you need to start a separate instance of browser (manual start) using the following arguments:
firefox.exe --marionette -profile C:\FirefoxTEMP
Above we open an instance of Firefox with --marionette turned on and we choose a fixed profile folder that were created just for selenium tasks.
Now, we will attach our automation to the already open Firefox window, by adding an argument to chose the same profile we started before.
Note: You must chose the same profile folder for the Webdriver use the open instance.
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--profile C:\\FirefoxTEMP");
driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("https://google.com");
Safari 10.0.1
macOS Sierra
When running Codeception command:
$I->waitForElementVisible(['css' => 'input[type=text][id=UserUsername]'], 30);
in an acceptance test in Safari with Selenium 3.0.1 I receive an error. The screenshot taken at failure clearly displays the element in question. The same test/command is successful in both Firefox and Chrome. The error:
Screenshot saved to /Applications/MAMP/htdocs/AutomatedTests/tests/_output/debug/FAILED1479307207.png
Unable to retrieve Selenium logs : The command 'GET /session/9BC56414-8934-4315-9293-B6E99720E318/log/types' is not implemented.
Command duration or timeout: 3 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'Cosettes-MacBook-Pro.local', ip: '10.0.1.75', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12602.2.14.0.5, cleanSession=true, platform=MAC, nativeEvents=true, locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 9BC56414-8934-4315-9293-B6E99720E318
Screenshot and page source were saved into '/Applications/MAMP/htdocs/AutomatedTests/tests/_output/' dir
ERROR
When I run the same test/command in Safari/Firefox/Chrome with Selenium 2.53.1 it finds the element with no problems.
Is there a known issue with this type of locator I'm not finding when going through the forums? Anyone have a suggestion for how to make this work?
Update 12-01-16: This now seems to be more of an issue with waitForElementVisible() command than the Locator. If I change the command to $I->waitForElement(['css' => 'input[type=text][id=UserUsername]'], 30); the test successfully moves forward till the next waitForElementVisible() command.
People say visibility checks are broken in the release version of Safari 10. You can try Safari Technology Preview, and if your issue is still there, we can conclude it's some other issue, not the broken visibility checks. If your issue is gone, it'll be not exactly your users' experience, but better than nothing anyways. Also you can try implementing your own visibility checks as a workaround using some script on the browser's side (e.g. this function looks good enough).
To run your tests in Safari Technology Preview, add
'safari.options': { technologyPreview: true }
to the capabilities.
See also my other answer on this subject.
Does anyone know how to setup the Microsoft Edge browser with Protractor?
I'm using Protractor (Javascript) and Gulp; NOT Java or C#.
Here's my Protractor config file:
exports.config = {
framework: 'cucumber',
seleniumArgs: ['-Dwebdriver.ie.driver=node_modules/protractor/selenium/MicrosoftWebDriver.exe'],
multiCapabilities: {
'browserName': 'MicrosoftEdge',
javascriptEnabled=true,
//'platform': 'windows',
// 'version': '11'
}
,
{
'browserName': 'chrome',
loggingPrefs: {
driver: 'DEBUG',
server: 'INFO',
browser: 'ALL'
}
}],
}
1. I specify the browser name which is 'MicrosoftEdge' then
2. I thought I would point to the EdgeDriver.exe just like I did and it worked for the IE browser.
What else am I missing, this successfully opens up the Edge browser but fails to navigate to a URL with error
var template = new Error(this.message);
^
UnknownError: null (WARNING: The server did not provide any stacktrace information)
Has anyone successfully set up Microsoft Edge with Protractor/CucumberJS?
I just had the same problem as you outlined,I noticed you and I are running the same build of Windows 10,
I have managed to find a solution to my problem if you see the small print around the download link on https://msdn.microsoft.com/en-us//library/mt188085(v=vs.85).aspx
You'll notice there are three driver versions try install the following one:
Windows 10 Fall 2015 Update, install Microsoft WebDriver Fall 2015 Update.
From the install directory take the 'MicrosoftWebDriver.exe' and replace your current one.
I think you are looking for is the Browser Fingerprint.
While not complete (including MS-Edge), it should point you in the correct direction..
https://en.wikipedia.org/wiki/Device_fingerprint#External_links
Especially - http://www.darkwavetech.com/fingerprint/fingerprint_code.html
Hope this helps!
I ended up doing the following to get Mircosoft Edge to launch from Protractor.
Here's where I got the driver for Microsoft Edge (https://www.microsoft.com/en-us/download/details.aspx?id=48212); you can install the .msi file and it'll give you a .exe which you can drop in to a location of your choice:
Here's my config file for Microsoft Edge:
exports.config = {
framework: 'cucumber',
//Microsoft Edge
seleniumArgs: ['-Dwebdriver.edge.driver=node_modules/protractor/selenium/MicrosoftWebDriver.exe'],
capabilities: {
'browserName': 'MicrosoftEdge',
'platform': 'windows',
// 'version': '11'
},
}
Please note if you wanted to just get IE11 then you would use this instead and make sure to point it to wherever you downloaded the ieDriver (http://www.seleniumhq.org/download/) to your local machine:
seleniumArgs: ['webdriver.ie.driver=node_modules/protractor/selenium/IEDriverServer.exe'],
And don't forget to change the browser name to 'browserName': 'internet explorer',
This is just a step closer to getting Protractor(Javascript and Gulp, please NO Java or C#) to work with Microsoft Edge on Windows 10 OS, this launches the Microsoft Edge browser; however I am still running into issues such as:
var template = new Error(this.message);
^
UnknownError: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6.95 seconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'DEV-6', ip: '10.10.50.25', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.edge.EdgeDriver
at new bot.Error
This is a work in progress so I'll update this post as I get more meaningful results; if anyone knows of how to avoid this error to successfully automate Microsoft Edge with Protractor please suggest it here.
And please note I am NOT using the Java or C# bindings which seem to be very popular on Google results; instead I am using Protractor with Javascript and gulp for my e2e tests. Any help much appreciated thanks.
For those who want to start a protractor test with edge, here is the relevant part of my protractor.conf :
seleniumArgs: ['-Dwebdriver.edge.driver=node_modules/protractor/selenium/MicrosoftWebDriver.exe'],
baseUrl: 'http://127.0.0.1:4321/index_protractor.html',
capabilities: {
'browserName': 'MicrosoftEdge'
},
So it's a mix between all you can read on the Internet (note that the case is important with MicrosoftEdge).
On the upside, Edge is started and I see the url changing, etc
On the downside, every test I tried failed with this error :
Message:
Failed: Error while running testForAngular: not implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'PORTABLE-SL3', ip: '192.168.43.171', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.edge.EdgeDriver
Capabilities [{acceptSslCerts=true, browserVersion=20.10240.16384.0, platformVersion=10, browserName=MicrosoftEdge, takesScreenshot=true, pageLoadStrategy=normal, takesElementScreenshot=true, platformName=windows, platform=ANY}]
Session ID: 732EDD82-B245-4020-8B0E-3FBE0428AAB6
So I guess the driver is not ready for Angular
EDIT:
Confirmed, adding this line before my browser.get fixed my error
browser.ignoreSynchronization=true;
I had to handle the wait for Angular manually though. Please note also that by.repeater was not working
I am using selenium 2.47 with Firefox v31. With this simple implementation:
public void navigateToHomePage() throws Throwable {
System.out.println("Navigate to Home");
driver = new FirefoxDriver();
driver.quit();
}
I got this error:
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
Build info: version: '2.47.0', revision: '0e4837e', time: '2015-07-29 22:49:49'
System info: host: 'ok-ThinkPad-SL500', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:99)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:90)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:276)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:223)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:212)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at cucumber.features.StepDefinitions.navigateToHomePage(StepDefinitions.java:24)
at ✽.Given I navigate to the home site(/home/ok/workspace/CucumberPOC/src/cucumber/features/UserRegistry.feature:6)
I don't know what is it??
This SocketLock error happens when Firefox tries to bind to port 7054 and fails because another instance already has that port locked.
An immediate solution is make sure you have NO Firefox tasks or process running in the background before launching a new driver. Kill them all and try launching again.
In the long run, you can avoid these issues by creating a new profile, change the port preferences to avoid locks, and then launch the driver using that profile. A short example:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, 7046)
driver = new FirefoxDriver(profile);
Unfortunately, when I was looking up the Java terms, I found that this feature was broken in Java's driver once, then it was fixed and then it broke in a later update, so even if you implement the solution I gave you, you may still get these errors in 2.47.
The fix was released in version 2.43.1, so if you don't need the newer versions for another issue/feature, you can try rolling back to a point where you can set a port preference successfully.
Not required reading: Some more technical details of the issue are in this pull request.
Unable to find/open Firefox Binary - webdriver/robot framework
My tests run fine in java and fitnesse. They also run fine when executing them through robot framework with Internet Explorer and Chrome. However when I execute them through Firefox, using 'new FirefoxDriver()', I receive the following error:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more
In the FirefoxBinary and FirefoxDriver classes these lines correspond to the following code:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
}
I have tried setting the path to the Firefox binary in my classpath, pythonpath (used by robotframework) and path. I have also written the following lines of code to try to force the binary to be found:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
I have tried to execute the tests on two computers, my work and home machines. Further I have tried to use a firefox profile created using firefox.exe –p and also by creating one in the java code. I have tried Firefox 6-8. Unfortunately none of these things have worked.
I am also using/have used:
Java 1.6
Selenium 2.9.0/2.13.0
Windows 7
I am unsure if this is related but as a work around I have been trying to get Firefox to run through a remote browser. I have been trying the following code:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);
However when I run the above I get the following error message:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
Does anyone have any idea on how to fix either of my problems?
Any help would be greatly appreciated, I feel very stuck on this issue atm. Two days of trying to get Firefox to work when Internet Explorer already does….. It feels as if the world is about to end.
Thanks,
James
EDIT:1
It is possible for me to run Firefox by using selenium-server.
James, FYI, URL for RemoteWebDriver appears incorrect in post above. Should be something more like "localhost:4444/wd/hub";? Interestingly, I'm having the opposite problem with Web Driver, having issues starting Firefox via RemoteWebDriver but Firefox runs fine via native FirefoxDriver. IE works fine over remote. – David Dec 4 '11 at 4:51
Thanks David!
I am not understanding why you have not configured your Firefox binary in your remote grids config.json file? That's how I would do it. Then, your DesiredCapabilities object would not need to define it. A hint can be found here.
If it works, the line in the JSON file might look like:
"binary": "C:/Program Files/Mozilla Firefox/firefox.exe",
I guess it doesn't allow you to dynamically set the binary location from your code, but perhaps you can try it that way to prove if it should work or not as a troubleshooting step.
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe"));
driver = new FirefoxDriver(binary, profile);
try this
This kind of issue obtained because of selenium web driver fail to find the .exe files of Firefox. Please check whether C:\Program Files (x86)\Mozilla Firefox you have exe file in the location and don’t forget to set environment variable having the java jdk path.
Source:- read [Solved Cannot find firefox binary in PATH Selenium][1]http://www.tech4crack.com/solved-cannot-find-firefox-binary-in-path/