Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97762

C# Selenium Webdriver- How to hide openfiledialog?

$
0
0

I have a small application written in C#, with Selenium webdriver (Chrome). I use this app to fill some textboxes and select some pictures to upload on a webpage.

The website wasn't designed by me, so I don't have any possibility to redesign it. There is a button on this website which needs to be clicked to select some pictures to upload. (in openfiledialog window)

In the program I find this button via xpath, the pictures paths are generated in another part of the program. When the picture is selected the program simulate to hit the Enter button so the upload begins.

The program works fine until it reaches the "picture upload" part. Until that point the app works in the background out of focus so i can do other things on the PC. But when the openfiledialog window appears it's steal the focus and make a mess with my other projects.

Is there any option to hide (not show at all) the openfiledialog window?

This is the current "file select and hit enter" part of my code:

{
  IWebElement btn_picture = driver.FindElement(By.XPath("//*[@class='class_name']"));

  Thread.Sleep(rand3);
  btn_picture.Click();

  int numpic1 = Convert.ToInt32(goods2.numericUpDownpic1.Value + 1);

  Random random2 = new Random();
  string elsokep = random2.Next(1, numpic1).ToString();

  string pth1 = goods2.textBox1pic.Text;
  string path1 = (pth1 + elsokep + ".png");

  int kepek = 1;

  Thread.Sleep(rand3);

  SendKeys.SendWait(path1);
  Thread.Sleep(4000);
  SendKeys.SendWait(@ "{Enter}");
}

Viewing all articles
Browse latest Browse all 97762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>