Selenium 2.0 - File Upload not working - selenium

I am unable to upload a file using selenium. I employ the below code:
Browser.FindElement(By.XPath(XPath)).SendKeys(path);
However, all that happens is that the file browse form comes up. The file does not get selected.
Does anyone know what I need to do to get this working, or a workaround? Many Thanks.

Refer to(saucelabs.com/resources/selenium-file-upload)
WebElement upload = driver.findElement(By.id("myfile"));
upload.sendKeys("/Users/sso/the/local/path/to/darkbulb.jpg");
driver.findElement(By.id("submit")).click();
driver.findElement(By.tagName("img"));
Also make sure you have given the path correctly. For example if the file is in d:\abc\pqr.txt, then path needs to be given as
"d:\\abc\\pqr.txt"
Mark this as an answer if this answers your question.
If not, please post your query!
Regards,
Sakshi

Related

Selenium Webdriver: Target url is not well formed

I have stored the URL in the excel file. I read the excel file and put the url in the java Properties. i retrieve the url from properties and try to launch it, but i get the error "Target URL  http://demo.guru99.com/V4/ is not well-formed." Please help.
Properties pInputOutPut= new Properties();
//here i have code to read the excel file and load the url to properties
_driver.get(pInputOutPut.getProperty("Url"));
I had it resolved by appending (http/https) prefixes to my URL which were missing when I encountered this error. Hope this helps!
Are you sure there aren't some special characters in your string that aren't visible? Microsoft products tend to add more than what is desired
This issue resolved by itself!!. I tried a couple of different urls it worked, then i switched back to my original url it worked too.

iTextSharp.text.Image.GetInstance changes Request.MapPath

I've been stuck on this problem all night. I've looked everywhere and can't seem to find anything related to my exact problem. On our IIS server we have a page that creates a pdf. We put an image in the header of the created PDF. This had been working properly until last night when we updated some unrelated code on different pages. Now when we try to create the PDF we get an error that the image file doesn't exist. Here's the weird part, iTextSharp.text.Image.GetInstance is changing the path we send to it?
Here's the line of code
Dim oImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Request.MapPath("~/images/" & sLogo))
If we output the results of Request.MapPath("~/images/" & sLogo) we receive
E:\Inetpub\sitename\images\logo.jpg
When we place it in in the iTextShart.text.Image.GetInstance() function our path output changes to
C:\Windows\SysWOW64\inetsrv\images\defaultlogo.jpg
You can see the logo itself changes too, it should be noted that we do use DefaultLogo.jpg in the case that a client doesn't use their own logo but all the ones i'm testing with do. The path E:\Inetpub\sitename\images does exist and logo.jpg does exist.
Here's the weirdest part, if i change the path from images to image
IE: iTextSharp.text.Image.GetInstance(Request.MapPath("~/image/" & sLogo))
the output will be
E:\Inetpub\sitename\image\logo.jpg
So i have no idea why images doesn't resolve.
Any help is greatly appreciated, and if this answer has been posted before and i just can't find it i'm very sorry, and if you could point me to that i would appreciate that as well.
I figured out my issue, and it's sheer stupidity on my part. The page we call to create the pdf had bad security on it. Basically we were looking for a session variable that didn't exist and redirected that page to a session time out notice. Removed that session check and it's working now!

Capybara open an html file in my computer

I have an html file in my computer and I want to open that file using Capybara to test it. Could you help me to solve this problem?
P/S: That html file is created automatically in my app. I do appreciate any idea helping me to solve this problem. Thanks :)
UPDATE:
Based on the capybara source code here, I found that I should use Capybara.current_session.driver.visit instead of page.visit. The problem is solved
I can confirm that the update to the question works (assuming the file is in the current directory):
filename = 'foo.html'
Capybara.current_session.driver.visit filename
If your file is located at /path/to/folder/file.html
Set Capybara.app to a folder containing this file:
Capybara.app = Rack::File.new('/path/to/folder')
and then
visit 'file.html'
should work for you
See also this gist for example
With simple relative file path I got errors:
Failure/Error: visit 'foo.html'
Selenium::WebDriver::Error::InvalidArgumentError:
invalid argument
I didn't want to switch Capybara.app to Rack::File and back, so I've tried this way and it works:
visit "file://#{__dir__}/foo.html"

Is it possible to use LinqPad's Hyperlinq() method to create a link to a file path

I really like how Hyperlinq allows you to hyperlinq to a website, but what about to a file? I would like to do something like this:
new Hyperlinq(#"C:\temp\afile.txt");
This is a bug in LINQPad - I've fixed it for the next build.
I have tried
new Hyperlinq(new Uri(#"C:\temp\afile.txt").ToString());
With this you get a valid hyperlink but I failed to click on it to open the file.
If you paste the link into a browser it works. I don't know if its a limitation of LinqPad.

Selenium IDE:After Recording the Application Functionalities in IDE,i use the tool to run.But,it is showing error like:

[error] Element //div[#id='divProjects']/table/tbody/tr/td[6]/i not found
i tried to use xpather,firebug inorder to find the id's and values of the object.But,it is not working for me.
please help me to solve my issue.
You can share the IDE script, it'll make easy to resolve the issue. You have to verify that you have got to the element when you are trying to perform any action on it.
Your xpath needs to be more relative. One thing you can try is to change the xpath to xpath:relative while recording in IDE. You can find this option on clicking on the dropdown