Page 1 of 1

Attach image in Internet Explorer

Posted: Fri Jun 20, 2014 12:44 am
by KennyLewis
Hello,

I am trying to attach an image in a web application. I have managed to get the code to work in Chrome because it detects that element. However, it does not work in cross browser testing.

Here is what I have:

Code: Select all

        private void Chrome_PathURL_ComboBox(string folderName)
        {
	        string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
	        DirectoryInfo parentDir = Directory.GetParent(baseDirectory);
	        string updatedDirectory = parentDir.Parent.FullName;
	        updatedDirectory = (updatedDirectory + folderName);
	        	
	        Report.Log(ReportLevel.Info, "Keyboard", "Key sequence 'yourtext' with focus on 'Open.PathURL_ComboBox'.", repo.Chrome_Upload.ChromePathURL_ComboBoxInfo);
	        repo.Chrome_Upload.ChromePathURL_ComboBox.PressKeys(updatedDirectory + "{Enter}");
        }
        
        private void FireFox_PathURL_ComboBox(string folderName)
        {
	        string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
	        DirectoryInfo parentDir = Directory.GetParent(baseDirectory);
	        string updatedDirectory = parentDir.Parent.FullName;
	        updatedDirectory = (updatedDirectory + folderName);
	        	
	        Report.Log(ReportLevel.Info, "Keyboard", "Key sequence 'yourtext' with focus on 'Open.PathURL_ComboBox'.", repo.FireFox_Upload.FireFoxPathURL_ComboBoxInfo);
	        repo.FireFox_Upload.FireFoxPathURL_ComboBox.PressKeys(updatedDirectory + "{Enter}");
        }
        
        private void IE_PathURL_ComboBox(string folderName)
        {
	        string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
	        DirectoryInfo parentDir = Directory.GetParent(baseDirectory);
	        string updatedDirectory = parentDir.Parent.FullName;
	        updatedDirectory = (updatedDirectory + folderName);
	        	
	        Report.Log(ReportLevel.Info, "Keyboard", "Key sequence 'yourtext' with focus on 'Open.PathURL_ComboBox'.", repo.IE_Upload.IEPathURL_ComboBoxInfo);
	        repo.IE_Upload.IEPathURL_ComboBox.PressKeys(updatedDirectory + "{Enter}");
        }
        
        
        public void BrowserImageFile(string folderName, string browser)
        {
        	{
        		if (repo.Chrome_Upload.ChromePathURL_ComboBox.Visible.Equals(true) )
        		{
		        		Chrome_PathURL_ComboBox(folderName);
        		}
        		else if (repo.FireFox_Upload.FireFoxPathURL_ComboBox.Visible.Equals(true) )
        		{
        			FireFox_PathURL_ComboBox(folderName);
        		}
	        	else if (repo.IE_Upload.Self.Visible.Equals(true) )
	        	{
		        		IE_PathURL_ComboBox(folderName);
	        	}

        	}
       	}
    }
The code will run correctly for the first browser, assuming Chrome is the first browser in the test. However, if I run it in FireFox it will time out.

I assume the if statement is incorrect, but was wondering if someone has any pointers. I have attached a screenshot of the current repository

Thanks!

Re: Attach image in Windows Explorer

Posted: Fri Jun 20, 2014 8:09 am
by mzperix
Hi,

This will sound too easy, but did you try to simplify the solution to use only one xpath?

As I can see, the only thing that is different between the xpath's of the browsers is the @title attribute.

Did you try to use only one element?

Just use an Application path like this one: /form[@title='File Upload' or @title='Open' or @title='Choose File to Upload']

Or even just /form ?

Best Regards,
Zoltan