I have to click on "choose File" button and it opens the fileopen dialog. I need to check if file exists or not. Here is the code
public static void UploadFile(IWebDriver driver, string photoLocation, string photoName)
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
IWebElement element = driver.FindElement(By.XPath("//*[text() ='Choose File']"));
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
js.ExecuteScript("arguments[0].click();", element);
// using "HandleOpenDialog" to locate and upload file
HandleOpenDialog hndOpen = new HandleOpenDialog();
hndOpen.fileOpenDialog(photoLocation, photoName);
Thread.Sleep(3000);
}
This code works properly if the file exists in the location. if it doesn't exists, i want code to look someplace else. The test is stuck there for long time and fails the test.
Can someone help me here?