2

Here is my scenario:

I am using Selenium Grid concept and we trigger test script execution from Hub (Machine-1) and script execute on chrome browser of Node machine (Machine-2). In one of my test script when I click on export button, it downloads an excel file in default download folder of Node machine (i.e. Machine-2)

Issue: Further in script I need to read content of the downloaded file, but as the downloaded file resides in Node machine, script does not able to access it from Hub.

So, How do we access downloaded file in Node machine from Hub machine ?

Sagar Bhavsar
  • 278
  • 3
  • 8
  • Hello @Sagar Did you find the solution, I have a similar situation, in my case I need to get some data from the Node to my local, and since my local is running in docker and GitHub I have a GitHub action to upload the data as artifacts, but I haven't been able to get the data back to my local. – Victor Andres Aguirre Fernande Nov 13 '22 at 05:13

1 Answers1

0

Local file detector

The Local File Detector allows the transfer of files from the client machine to the remote server. In case a test needs to upload a file to a web application, a remote WebDriver can automatically transfer the file from the local machine to the remote web server during runtime. This allows the file to be uploaded from the remote machine running the test. It is not enabled by default and can be enabled as follows:

  • Java:

    driver.setFileDetector(new LocalFileDetector());
    
  • Python:

    from selenium.webdriver.remote.file_detector import LocalFileDetector
    
    driver.file_detector = LocalFileDetector()
    
  • C#:

    var allowsDetection = this.driver as IAllowsFileDetection;
    if (allowsDetection != null)
    {
       allowsDetection.FileDetector = new LocalFileDetector();
    }
    

This usecase

If you are running your tests on Selenium Grid then you need to let your remote driver know that the file that needs to be uploaded is residing on the local machine and not on remote machine. In those cases, to upload a file from the client machine to the remote server, WebDriver can automatically transfer the file from the local machine to the remote web server during runtime you can use the following code block:

WebElement addFile = driver.findElement(By.xpath("//input[@type='file']"));
((RemoteWebElement)addFile).setFileDetector(new LocalFileDetector());
addFile.sendKeys("C:\\daten\\test2.xml");

Outro

Selecting and uploading files while running your tests on Selenium Grid

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks @DebanjanB for your quick response. The solution which you have provided is useful when file is in Hub machine and you want to access it in the Node machine. But here in my case, via selenium script file will be downloaded in the Node machine (Machine-2) at runtime and then we need to access it from Hub machine (Machine-1). – Sagar Bhavsar Dec 17 '20 at 04:53