I need to upload file from local storage

Hello,

I am trying to upload file using browse button but fails to upload any document. Here, Browser button "type=“submit”

I used:

WebUI.uploadFile(findTestObject(“PhotoBrowse”),‘C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg’)

also, try with custom keyword but can’t upload file

I would appreciate any help.

what error message are you getting when you try to do that?

HI B L,

Thanks for your prompt reply…

I found the solution for upload file,

import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection

public class Uploadfile {

@Keyword

def uploadFile(TestObject to, String filePath) {

WebUI.click(to)

StringSelection ss = new StringSelection(filePath);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

robot.delay(1000);

robot.keyPress(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_V);

robot.keyRelease(KeyEvent.VK_V);

robot.delay(1000);

robot.keyRelease(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

}

I used this custom keyword in my script

CustomKeywords.‘com.ll.utilities.Uploadfile.uploadFile’(findTestObject(‘Object Repository/AddClearance/Browsebtn’),‘C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg’)

WebUI.verifyElementPresent(findTestObject(“Object Repository/AddClearance/ImageVerification”),3)

1 Like

Hello I am beginner. I also need to upload a csv file to the website but I could not.

Can you describe it in a simple way I can understand. I’m just connecting to the website right now. I’m choosing where to install. I cannot scroll through the xpath path and then to open the installation page. So I can’t open the loading page on the web page and I can’t load the file.

The flow is below.

Can you show me where to fix it.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.thoughtworks.selenium.Selenium

import org.openqa.selenium.firefox.FirefoxDriver

import org.openqa.selenium.WebDriver

import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium

import static org.junit.Assert.*

import java.util.regex.Pattern

import static org.apache.commons.lang3.StringUtils.join

WebUI.openBrowser(‘https://www.katalon.com/’)

def driver = DriverFactory.getWebDriver()

String baseUrl = “https://www.katalon.com/

selenium = new WebDriverBackedSelenium(driver, baseUrl)

selenium.open(“https://airtable.com/”)

selenium.click(“xpath=(.//*[normalize-space(text()) and normalize-space(.)=‘Global Port copy’])[1]/following::i[1]”)

selenium.selectFrame(“index=2”)
------doesn’t work after--------

selenium.click("/html/body/div[1]/div/div/div/div")

selenium.type(“xpath=(.//*[normalize-space(text()) and normalize-space(.)=‘Or click to choose a file…’])[1]/preceding::input[1]”, “C:\\fakepath\\deneme_x.csv”)

selenium.click(“xpath=(.//*[normalize-space(text()) and normalize-space(.)=‘Cancel’])[1]/following::button[1]”)