How to upload image to web page in Saucelabs test by Selenium in c#? -
I have to upload any image on the web page to create an online shop to go on trial. I have to click on the button to upload, after which I have to give the directory of the file, but I can not give the local directory because the test runs on the SOSBab on the VOM. How to solve the problem?
By setting the file detector, the LocalfilDDatak class. Your code will look something like this:
// Warning !! Without the benefit of an IDE, uncharted code written from memory can probably not work properly or can compile without modification. // Assume that the driver is a properly instant iWebDriver object, which is used with a remote service (with SauceLabs or similar). IAllowsFileDetection file as a Dynamic Directory = Driver IAllowsFileDetection; FileDetectionDriver.FileDetector = new localfiledetter (); IWebElement File Element = driver.FindElement (By.Id ("idOfFileInputElement")); FileElement.SendKeys (@ "C: \ path \ \ local.file"); SendKeys method will first upload the file from the local system to the remote machine on which the code is actually running. Then SendKeys removes the file by using the local file path on the remote machine & lt; Input & gt; in the element.
Comments
Post a Comment