public void Searchplayers() { driver.Navigate().GoToUrl("https://www.indiansuperleague.com/"); driver.Manage().Window.Maximize(); string ReadExcel; int rctn = 6; excel.Application x1app = new excel.Application(); excel.Workbook x1workbook = x1app.Workbooks.Open(@"D:\Automation\ISL\Player search file\player_data1.xlsx"); excel.Worksheet x1worksheet = x1workbook.Sheets[1]; excel.Range x1range = x1worksheet.UsedRange; for (int i = 6; i <= rctn; i++) { for (int j = 2; j <= 78; j++) { ReadExcel = x1range.Cells[i][j].Text.ToString(); driver.FindElement(By.XPath("/html/body/div[1]/header/section/div/div/div[3]/div/div[2]/div[1]/ul/li[5]/a")).Click(); var search = driver.FindElement(By.XPath("/html/body/div[1]/div[1]/div/div[2]/input")); search.SendKeys(ReadExcel); search.SendKeys(Keys.Enter); var visible = driver.FindElement(By.XPath("//*[@id='cookiebtn']")); if (visible.Displayed) { //Assert.AreEqual(true, visible.Displayed); visible.Click(); } /* FunctionalLibrary.TryFindElement(driver, "//*[@id='cookiebtn']" ); * * var visible = IsElementVisible(element); * if (visible) * { * element.Click(); * }*/ var viewprofile = driver.FindElement(By.Id("player-list")); var action1 = new OpenQA.Selenium.Interactions.Actions(driver); ((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(document.body.scrollHeight, 0)"); action1.MoveToElement(viewprofile); action1.Perform(); viewprofile = new WebDriverWait(driver, new TimeSpan(0, 1, 0)) .Until(driver => driver.FindElement(By.Id("player-list"))); var playername = driver.FindElement(By.CssSelector(".article-name")).Text; if (ReadExcel.Equals(playername)) { Debug.WriteLine(playername, "player name is correct"); } else { Debug.WriteLine(playername, "player name is incorrect"); } var webe = driver.FindElement(By.Id("player-list")); var href = webe.FindElement(By.CssSelector("a")).GetAttribute("href"); // WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1)); //wait.Until(ExpectedConditions.UrlContains(href)); if (href == null) { Debug.WriteLine(playername, "Player not clikable"); } else { Debug.WriteLine(playername, "player is clikable"); webe.Click(); Thread.Sleep(1000); var playerdetail = driver.FindElement(By.CssSelector(".si-player-name")).Text; if (playername.Equals(playerdetail)) { Debug.WriteLine("Redirected on detail page"); } } Thread.Sleep(2000); /*var viewprofilesroll = driver.FindElement(By.CssSelector(".article-content")); * var action2 = new OpenQA.Selenium.Interactions.Actions(driver); * ((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(document.body.scrollHeight, 0)"); * action2.MoveToElement(viewprofilesroll); * action2.Perform(); * viewprofilesroll = new WebDriverWait(driver, new TimeSpan(0, 1, 0)) * .Until(driver => driver.FindElement(By.CssSelector(".article-content")));*/ //svar viewprofilesroll = driver.FindElement(By.CssSelector(".si-player-name")); } } }
public void Searchplayers() { driver.Navigate().GoToUrl("https://www.indiansuperleague.com/"); driver.Manage().Window.Maximize(); string ReadExcel; int rctn = 6; excel.Application x1app = new excel.Application(); excel.Workbook x1workbook = x1app.Workbooks.Open(@"D:\Automation\ISL\Player search file\player_data1.xlsx"); excel.Worksheet x1worksheet = x1workbook.Sheets[1]; excel.Range x1range = x1worksheet.UsedRange; for (int i = 6; i <= rctn; i++) { for (int j = 2; j <= 78; j++) { ReadExcel = x1range.Cells[i][j].Text.ToString(); driver.FindElement(By.XPath("/html/body/div[1]/header/section/div/div/div[3]/div/div[2]/div[1]/ul/li[5]/a")).Click(); var search = driver.FindElement(By.XPath("/html/body/div[1]/div[1]/div/div[2]/input")); search.SendKeys(ReadExcel); search.SendKeys(Keys.Enter); var visible = driver.FindElement(By.XPath("//*[@id='cookiebtn']")); if (visible.Displayed) { //Assert.AreEqual(true, visible.Displayed); visible.Click(); } var record = driver.FindElement(By.XPath("/html/body/div[1]/section/myapp/section/div/div/div/div/section/component/div/div/div[2]/div[2]/span")).Text; if (record.StartsWith("0 records for")) { Console.WriteLine(ReadExcel, "player is deleted"); } /* FunctionalLibrary.TryFindElement(driver, "//*[@id='cookiebtn']" ); * * var visible = IsElementVisible(element); * if (visible) * { * element.Click(); * }*/ else if (IsElementPresent(By.Id("player-list"))) { var viewprofile = driver.FindElement(By.Id("player-list")); var action1 = new OpenQA.Selenium.Interactions.Actions(driver); ((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(document.body.scrollHeight, 0)"); action1.MoveToElement(viewprofile); action1.Perform(); viewprofile = new WebDriverWait(driver, new TimeSpan(0, 1, 0)) .Until(driver => driver.FindElement(By.Id("player-list"))); var playername = driver.FindElement(By.CssSelector(".article-name")).Text; if (ReadExcel.Equals(playername)) { Console.WriteLine(playername, "player name is correct"); } else { Console.WriteLine(playername, "player name is incorrect"); } var webe = driver.FindElement(By.Id("player-list")); var href = webe.FindElement(By.CssSelector("a")).GetAttribute("href"); if (href == null) { Console.WriteLine(playername, "Player not clikable"); } else { Debug.WriteLine(playername, "player is clikable"); webe.Click(); Thread.Sleep(1000); var playerdetail = driver.FindElement(By.CssSelector(".si-player-name")).Text; if (playername.Equals(playerdetail)) { Console.WriteLine(playername, "Redirected on detail page"); } var error = driver.FindElement(By.CssSelector(".txt-1")).Text; if (error.Equals("Oops!Page Not Found.")) { String currenturl = driver.Url; Console.WriteLine(currenturl, "404 page"); } } } else { String currenturl = driver.Url; Console.WriteLine(currenturl, "player profile isn't available"); } } } }