/// <summary> /// Return a list of web element using the javascript to find element /// </summary> /// <param name="pageNameToSwitchTo"></param> /// <param name="frameNameToSwitchTo"></param> /// <param name="scriptToExecute"></param> /// <returns></returns> public ReadOnlyCollection <IWebElement> ExecuteJavaScriptIWebElementList(string pageNameToSwitchTo, string frameNameToSwitchTo, string scriptToExecute) { SAFINCALog.Debug("scriptToExecute: " + scriptToExecute); driver = FindWebDriverElement.SwitchToFrameOrWindowByName(this.driver, pageNameToSwitchTo, frameNameToSwitchTo); IJavaScriptExecutor iJavaScriptExecutor = (IJavaScriptExecutor)driver; ReadOnlyCollection <IWebElement> iWebElementList = (ReadOnlyCollection <IWebElement>)iJavaScriptExecutor.ExecuteScript(scriptToExecute); SAFINCALog.Debug("iWebElementList: " + iWebElementList); return(iWebElementList); }
public void SeleniumSetup() { try { Console.WriteLine("Starting Driver..........."); String browser = ConfigurationManager.AppSettings["WEB_BROWSER_TO_RUN"]; var options = new InternetExplorerOptions { IntroduceInstabilityByIgnoringProtectedModeSettings = true, EnsureCleanSession = true, //ForceCreateProcessApi=true EnableNativeEvents = false, RequireWindowFocus = false, IgnoreZoomLevel = true }; ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--test-type"); chromeOptions.AddArguments("chrome.switches", "--disable-extensions"); chromeOptions.AddArgument("start-maximized"); chromeOptions.AddArgument("--enable-automation"); chromeOptions.AddArgument("test-type=browser"); chromeOptions.AddArgument("disable-infobars"); if (browser.Contains("Internet")) { driver = new InternetExplorerDriver(TestContext.DeploymentDirectory, options); } else if (browser.Contains("Chrome")) { driver = new ChromeDriver(chromeOptions); } // driver = new ChromeDriver(); else { driver = null; } if (driver != null) { // Javascript Class javaScriptCalls = new JavaScriptCalls(); javaScriptCalls.Driver = driver; //Find Web Driver findWebDriverElement = new FindWebDriverElement(); findWebDriverElement.Driver = driver; findWebDriverElement.JavaScriptCalls = javaScriptCalls; //Operate Web Element operateOnWebDriverElement = new OperateOnWebDriverElement(); operateOnWebDriverElement.FindWebDriverElement = findWebDriverElement; operateOnWebDriverElement.JavaScriptCalls = javaScriptCalls; SVLGridOperation = new SVLGridOperation(); safeebbalog = new SAFINCALog(); switcher = new IframeSwitcher(); incaFunction = new IncaGenericFunction(); GoToSite(ConfigParameters.WEB_APPLICATION_URL); // driver.Manage().Window.Maximize(); // } // else // { // SAFINCALog.Debug("Browser type not specified in the config file..........."); // } } } catch (Exception e) { SAFINCALog.Debug("Error Starting Web Driver..........."); Console.WriteLine(e.StackTrace); } }