Woodman81 Woodman81 - 3 months ago 7
C# Question

Selenium webdriver script failing to locate button even with ID

I'm hoping this is easier than it seems and I've just gone snow blind trying to fix it! Your help would be massively appreciated on this.

I am using the PageObject Model (I think!) to create my tests. I have an object which replicates the browsing for and uploading of an image, which I am having to call an AutoIt script to accomplish. This works but having uploaded the image the 'upload' button is not being located even though it has an ID attribute.

It is correctly being enabled following the file selection so unsure what I'm missing.

The code for the PageObject is:

public void AddImage(string FileDescription, int DocNo, int Revision, string StatusLstItem, string CreationDate)
{

driver.FindElement(By.Id("Button1")).Click();
driver.SwitchTo().Window("FileDetails");
driver.FindElement(By.Id("Description1")).Clear();
driver.FindElement(By.Id("Description1")).SendKeys(FileDescription);
driver.FindElement(By.Id("DocNo1")).Clear();
driver.FindElement(By.Id("DocNo1")).SendKeys(DocNo.ToString());
driver.FindElement(By.Id("revision1")).Clear();
driver.FindElement(By.Id("revision1")).SendKeys(Revision.ToString());
new SelectElement(driver.FindElement(By.Id("FileStatus1"))).SelectByText(StatusLstItem);
driver.FindElement(By.Id("creationDate1")).Clear();
driver.FindElement(By.Id("creationDate1")).SendKeys(CreationDate);
IWebElement element = driver.FindElement(By.Id("Filename1"));
element.Click();
Process.Start("C:\\Users\\Tom\\Desktop\\FileUploadCr.exe");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement upload = driver.FindElement(By.Id("action1"));
upload.Click();
}


I am then calling the '
AddImage
' method from the test class using the following:

[Test]
public void ItemChecks()
{
InformationObject informationObject = new InformationObject(driver);

informationObject.ExpandAllButton();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
informationObject.AddImage("SampleDesc", 01, 01, "Approved", "01/10/2012");
informationObject.ClickUpdateButtonOne();
}


For some reason it is not finding/clicking the 'action1' upload button. I have tried switching back to the 'FileDetails' window but this also does not work.

Any ideas what is I'm missing???

FYI - the code for the Upload button is:

<input type="Submit" value="Upload" id="action1" disabled=""/>


UPDATE - the amended + working PageObject method now looks like this:

public void AddImage(string FileDescription, int DocNo, int Revision, string StatusLstItem, string CreationDate)
{
driver.FindElement(By.Id("Button1")).Click();
driver.SwitchTo().Window("FileDetails");
IWebElement element = driver.FindElement(By.Id("Filename1"));
element.Click();
Process.Start("C:\\Users\\Tom\\Documents\\Visual Studio 2010\\Projects\\AutoIt_Files\\FileUploadCr.exe");
Thread.Sleep(1000);
driver.FindElement(By.Id("Description1")).Clear();
driver.FindElement(By.Id("Description1")).SendKeys(FileDescription);
driver.FindElement(By.Id("DocNo1")).Clear();
driver.FindElement(By.Id("DocNo1")).SendKeys(DocNo.ToString());
driver.FindElement(By.Id("revision1")).Clear();
driver.FindElement(By.Id("revision1")).SendKeys(Revision.ToString());
new SelectElement(driver.FindElement(By.Id("FileStatus1"))).SelectByText(StatusLstItem);
driver.FindElement(By.Id("creationDate1")).Clear();
driver.FindElement(By.Id("creationDate1")).SendKeys(CreationDate);
driver.SwitchTo().Window("FileDetails");
Thread.Sleep(1000);
IWebElement upload = driver.FindElement(By.Id("action1"));
upload.Click();
Thread.Sleep(1000);
driver.SwitchTo().Alert().Dismiss(); //Ignore this, just an alert that displays following upload and not part of the solution
}

Answer

Try Using

driver.FindElement(By.id("action1")).submit();
Comments