S
Sriram_CS
Guest
Hi,
I'm new to selenium. I try to download files in ie browser. I'm getting below error massage
{"Cannot click on element"}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "Cannot click on element"
Source: "WebDriver"
StackTrace: " at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebElement.Click()\r\n at Automation.QA_Report.DownloadAllReport(String textToType) in C:\\Users\\Sriram.Engaiahraj\\Source\\Repos\\Automation\\Automation\\QA_Report.cs:line 102"
TargetSite: {Void UnpackAndThrowOnError(OpenQA.Selenium.Remote.Response)}
If i use Chrome browser Working fine. Could you please guide me.
My Code :
public class QA_Report
{
private readonly IWebDriver driver;
int MaxRun = 0;
public QA_Report(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}
public string Url
{
get
{
return @"https://**************************.aspx";
}
}
[FindsBy(How = How.Name, Using = "loginfmt")]
public IWebElement txtLogin { get; set; }
[FindsBy(How = How.Id, Using = "idSIButton9")]
public IWebElement btnLogin { get; set; }
[FindsBy(How = How.Id, Using = "idSIButton9")]
public IWebElement btnYes { get; set; }
[FindsBy(How = How.Id, Using = "MainGrid")]
public IWebElement GridMain { get; set; }
[FindsBy(How =How.TagName, Using = "tr")]
public IList<IWebElement> Rows { get; set; }
[FindsBy(How = How.TagName, Using = "td")]
public IList<IWebElement> Cells { get; set; }
[FindsBy(How = How.LinkText, Using = "Download CSV File")]
public IWebElement LikDownload { get; set; }
[FindsBy(How=How.Id,Using= "sp_1_MainGrid_toppager")]
public IWebElement PageCount { get; set; }
[FindsBy(How=How.ClassName,Using= "ui-pg-input")]
public IWebElement txtNextPage { get; set; }
[FindsBy(How=How.Name,Using = "Iwanttogenerateareportand")]
public IWebElement CheckPage { get; set; }
public void Navigate()
{
this.driver.Navigate().GoToUrl(this.Url);
}
public void DownloadAllReport(string textToType)
{
try{
MaxRun++;
if (!IsElementPresent(By.Id("MainGrid")))
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(90);
Thread.Sleep(5500);
this.txtLogin.SendKeys(textToType);
this.btnLogin.Click();
Thread.Sleep(10500);
this.btnYes.Click();
Thread.Sleep(5000);
}
if (!IsElementPresent(By.Id("MainGrid")))
{
Navigate();
//do if exists
}
// Rows = this.GridMain.FindElements(By.TagName("tr"));
int pageCount = Convert.ToInt32(this.PageCount.Text);
for (int i = 1; i <= pageCount; i++)
{
if (i != 1)
{
this.txtNextPage.Clear();
this.txtNextPage.SendKeys(i.ToString());
this.txtNextPage.SendKeys(Keys.Enter);
Thread.Sleep(1000);
}
Rows = this.GridMain.FindElements(By.TagName("tr"));
foreach (IWebElement row in Rows)
{
Thread.Sleep(1000);
IList<IWebElement> cells = row.FindElements(By.TagName("td"));
if (cells[7].Text.Contains("Download CSV File"))
{
LikDownload = cells[7].FindElement(By.LinkText("Download CSV File"));
LikDownload.Click();
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
// if (MaxRun <= 3)
//{
//Navigate();
//}
}
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
}
Regards,
Sriram e
Continue reading...
I'm new to selenium. I try to download files in ie browser. I'm getting below error massage
{"Cannot click on element"}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "Cannot click on element"
Source: "WebDriver"
StackTrace: " at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebElement.Click()\r\n at Automation.QA_Report.DownloadAllReport(String textToType) in C:\\Users\\Sriram.Engaiahraj\\Source\\Repos\\Automation\\Automation\\QA_Report.cs:line 102"
TargetSite: {Void UnpackAndThrowOnError(OpenQA.Selenium.Remote.Response)}
If i use Chrome browser Working fine. Could you please guide me.
My Code :
public class QA_Report
{
private readonly IWebDriver driver;
int MaxRun = 0;
public QA_Report(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}
public string Url
{
get
{
return @"https://**************************.aspx";
}
}
[FindsBy(How = How.Name, Using = "loginfmt")]
public IWebElement txtLogin { get; set; }
[FindsBy(How = How.Id, Using = "idSIButton9")]
public IWebElement btnLogin { get; set; }
[FindsBy(How = How.Id, Using = "idSIButton9")]
public IWebElement btnYes { get; set; }
[FindsBy(How = How.Id, Using = "MainGrid")]
public IWebElement GridMain { get; set; }
[FindsBy(How =How.TagName, Using = "tr")]
public IList<IWebElement> Rows { get; set; }
[FindsBy(How = How.TagName, Using = "td")]
public IList<IWebElement> Cells { get; set; }
[FindsBy(How = How.LinkText, Using = "Download CSV File")]
public IWebElement LikDownload { get; set; }
[FindsBy(How=How.Id,Using= "sp_1_MainGrid_toppager")]
public IWebElement PageCount { get; set; }
[FindsBy(How=How.ClassName,Using= "ui-pg-input")]
public IWebElement txtNextPage { get; set; }
[FindsBy(How=How.Name,Using = "Iwanttogenerateareportand")]
public IWebElement CheckPage { get; set; }
public void Navigate()
{
this.driver.Navigate().GoToUrl(this.Url);
}
public void DownloadAllReport(string textToType)
{
try{
MaxRun++;
if (!IsElementPresent(By.Id("MainGrid")))
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(90);
Thread.Sleep(5500);
this.txtLogin.SendKeys(textToType);
this.btnLogin.Click();
Thread.Sleep(10500);
this.btnYes.Click();
Thread.Sleep(5000);
}
if (!IsElementPresent(By.Id("MainGrid")))
{
Navigate();
//do if exists
}
// Rows = this.GridMain.FindElements(By.TagName("tr"));
int pageCount = Convert.ToInt32(this.PageCount.Text);
for (int i = 1; i <= pageCount; i++)
{
if (i != 1)
{
this.txtNextPage.Clear();
this.txtNextPage.SendKeys(i.ToString());
this.txtNextPage.SendKeys(Keys.Enter);
Thread.Sleep(1000);
}
Rows = this.GridMain.FindElements(By.TagName("tr"));
foreach (IWebElement row in Rows)
{
Thread.Sleep(1000);
IList<IWebElement> cells = row.FindElements(By.TagName("td"));
if (cells[7].Text.Contains("Download CSV File"))
{
LikDownload = cells[7].FindElement(By.LinkText("Download CSV File"));
LikDownload.Click();
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
// if (MaxRun <= 3)
//{
//Navigate();
//}
}
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
}
Regards,
Sriram e
Continue reading...