public ITargetLocator getProxy()
        {
            ProxyGenerator generator = new ProxyGenerator(new PersistentProxyBuilder());
            ITargetLocator proxy     = generator.CreateInterfaceProxyWithTarget(typeof(ITargetLocator), targetLocator, interceptor) as ITargetLocator;

            return(proxy);
        }
 /// <summary>
 /// This method Navigate control to iframe
 /// </summary>
 /// <param name="frameid">FrameId</param>
 public static void NavigateToIFrame(string frameid)
 {
     Thread.Sleep(2000);
     currentframe = driver.SwitchTo();
     currentframe.Frame(frameid);
     log.Info("Moved to IFrame");
 }
Esempio n. 3
0
        public void Switch(string windowName)
        {
            ControlOp      co     = new ControlOp();
            ITargetLocator target = driver.SwitchTo();

            target.Window(co.FindWindowHandle(windowName).ToString("X8"));
        }
Esempio n. 4
0
        public static IWebDriver WindowForceBackground(this ITargetLocator targetLocator, string windowName)
        {
            IWebDriver driver = targetLocator.Window(windowName);

            try
            {
                foreach (Process process in SetWindowPosition.GetPrimaryProcesses("chrome"))
                {
                    if (process.Id != 0)
                    {
                        SetWindowPosition.ForceWindowToStayOnBottom(process);
                        Console.WriteLine("Successfully pushed back a chrome window with PID: " + process.Id);
                    }
                    else
                    {
                        Console.WriteLine("Left chrome window with PID " + process.Id + " untouched.");
                    }
                }

                Console.WriteLine("Successfully pushed back the chrome windows.");
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to push back the chrome windows.");
            }

            return(driver);
        }
Esempio n. 5
0
        public ITargetLocator SwitchTo()
        {
            ITargetLocator locator = null;


            return(locator);
        }
        public IWebDriver FramesDoScroll(FrameChain frameChain)
        {
            logger_.Verbose("EyesTargetLocator.framesDoScroll(frameChain)");
            ITargetLocator targetLocator = driver_.SwitchTo();

            targetLocator.DefaultContent();
            IPositionProvider scrollProvider = new ScrollPositionProvider(logger_, jsExecutor_, driver_.Eyes.GetCurrentFrameScrollRootElement());

            defaultContentPositionMemento_ = scrollProvider.GetState();
            foreach (Frame frame in frameChain)
            {
                logger_.Verbose("Scrolling by parent scroll position...");
                Point frameLocation = frame.Location;
                scrollProvider.SetPosition(frameLocation);
                logger_.Verbose("Done! Switching to frame...");
                targetLocator.Frame(frame.Reference);
                Frame newFrame = driver_.GetFrameChain().Peek();
                newFrame.ScrollRootElement            = frame.ScrollRootElement;
                newFrame.ScrollRootElementInnerBounds = frame.ScrollRootElementInnerBounds;
                logger_.Verbose("Done!");
            }

            logger_.Verbose("Done switching into nested frames!");
            return(driver_);
        }
 public EUETargetLocatorProxy(IWebDriver driver, ITargetLocator targetLocator, EUEEntryHandler dataExchangeEntryHelper, EUEConfiguration conf)
 {
     this.driver                  = driver;
     this.targetLocator           = targetLocator;
     this.dataExchangeEntryHelper = dataExchangeEntryHelper;
     this.conf   = conf;
     interceptor = new EUEElementInterceptor(driver, dataExchangeEntryHelper, conf, METHODS);
 }
Esempio n. 8
0
 public ZombieContextUpdater(TargetChaser chaser,
                             ITargetLocator targetLocator,
                             IPositionDetector positionDetector)
 {
     _chaser           = chaser;
     _targetLocator    = targetLocator;
     _positionDetector = positionDetector;
 }
Esempio n. 9
0
 public ITargetLocator SwitchTo()
 {
     if (targetLocator_ == null)
     {
         targetLocator_ = new EyesWebDriverTargetLocator(this, Logger_, RemoteWebDriver.SwitchTo());
     }
     return(targetLocator_);
 }
Esempio n. 10
0
        public TargetLocatorInstance(ObjectInstance prototype, ITargetLocator targetLocator)
            : this(prototype)
        {
            if (targetLocator == null)
            {
                throw new ArgumentNullException("targetLocator");
            }

            m_targetLocator = targetLocator;
        }
 public static IAlert WaitAlert(this ITargetLocator locator, int seconds = 10)
 {
     while (true)
     {
         try { return(locator.Alert()); }
         catch (NoAlertPresentException) when(--seconds >= 0)
         {
             Thread.Sleep(1000);
         }
     }
 }
 public static IAlert AlertOrNull(this ITargetLocator locator)
 {
     try
     {
         return(locator.Alert());
     }
     catch (NoAlertPresentException)
     {
         return(null);
     }
 }
Esempio n. 13
0
 public static IAlert?TryGetAlert(this ITargetLocator locator)
 {
     try
     {
         return(locator.Alert());
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Switches into every frame in the list. This is used as way to switch into nested frames in a single call.
        /// </summary>
        /// <param name="framesPath">The path to the frame to check. This is a list of frame names/IDs (where each frame is nested in the previous frame).</param>
        /// <returns>The WebDriver with the switched context.</returns>
        public IWebDriver Frames(string[] framesPath)
        {
            logger_.Log(TraceLevel.Debug, Stage.General, StageType.Called);
            ITargetLocator targetLocator = driver_.SwitchTo();

            foreach (string frameNameOrId in framesPath)
            {
                targetLocator.Frame(frameNameOrId);
            }
            return(driver_);
        }
Esempio n. 15
0
        public void WindowProcess_Demo1()
        {
            // 1. 获取窗口定位对象
            IWebDriver driver = new FirefoxDriver();
            //省略部分代码... ...
            ITargetLocator locator = driver.SwitchTo();

            driver = locator.Window("windowName");
            //后续操作... ...
            driver.Quit();
        }
Esempio n. 16
0
        public void QQLogin()
        {
            dynamic type             = (new UnitTest1()).GetType();
            string  currentDirectory = Path.GetDirectoryName(type.Assembly.Location);
            var     driver           = new ChromeDriver(currentDirectory);

            driver.Url = "https://qzone.qq.com/";
            try
            {
                //切换语法有两种,一种是根据索引切换,另外一种根据iframe名称切换
                //这里我们使用name切换
                ITargetLocator tagetLocator = driver.SwitchTo();
                //tagetLocator.Frame(1);  //frame index.
                tagetLocator.Frame("login_frame");  //frame frame name.
                var switchLogin = driver.FindElementByCssSelector("#switcher_plogin");
                switchLogin.Click();
                var userName = driver.FindElementByXPath("//*[@id='u']");
                //这里的userName就是用户名的文本框
                //设置用户名的值
                userName.SendKeys("123456");
                var pwd = driver.FindElementByXPath("//*[@id='p']");
                pwd.SendKeys("********");
                var btnLogin = driver.FindElementByXPath("//*[@id='login_button']");
                //这里是判断登录按钮是否可见,可以不写,直接调用click方法
                if (btnLogin != null && btnLogin.Displayed == true)
                {
                    btnLogin.Click();
                }
                System.Threading.Thread.Sleep(3000);
                //*[@id="menuContainer"]/div/ul/li[5]/a
                var msgDom = driver.FindElementByXPath("//*[@id='menuContainer']/div/ul/li[5]/a");
                if (msgDom != null && msgDom.Displayed == true)
                {
                    msgDom.Click();
                }
                //页面跳转,切换到说说页面的说说列表Iframe
                ITargetLocator t = driver.SwitchTo();
                //这里我们换一种获取元素方法,直接使用css获取
                //xpath //*[@id="app_container"]/iframe
                //css #app_container > iframe
                IWebElement frame = driver.FindElementByCssSelector("#app_container > iframe");
                t.Frame(frame);
                //定义说说集合
                var dataAll = new List <MessageInfo>();
                //第一页开始,pageIndex 默认0
                //定义汉字方法为了直观描述功能,不要在意这些细节
                说说内容获取(driver, dataAll, 0);
            }
            finally
            {
                driver.Quit();
            }
        }
 public EyesWebDriverTargetLocator(EyesWebDriver driver, Logger logger, ITargetLocator targetLocator)
 {
     driver_        = driver;
     logger_        = logger;
     targetLocator_ = targetLocator;
     jsExecutor_    = new SeleniumJavaScriptExecutor(driver_);
     if (driver.Eyes != null)
     {
         scrollPositionProvider_ = SeleniumPositionProviderFactory.GetPositionProvider(
             logger_, StitchModes.Scroll, jsExecutor_, driver.Eyes.GetCurrentFrameScrollRootElement(), driver.Eyes.userAgent_);
     }
 }
        /// <summary>
        /// Switches into every frame in the list. This is used as way to switch into nested frames in a single call.
        /// </summary>
        /// <param name="framesPath">The path to the frame to check. This is a list of frame names/IDs (where each frame is nested in the previous frame).</param>
        /// <returns>The WebDriver with the switched context.</returns>
        public IWebDriver Frames(string[] framesPath)
        {
            logger_.Verbose("(framesPath)");
            ITargetLocator targetLocator = driver_.SwitchTo();

            foreach (string frameNameOrId in framesPath)
            {
                logger_.Debug("Switching to frame '{0}'...", frameNameOrId);
                targetLocator.Frame(frameNameOrId);
            }
            logger_.Verbose("Done switching into nested frames!");
            return(driver_);
        }
        /// <summary>
        ///     <inheritdoc cref="Drelanium.Alert" />
        /// </summary>
        /// <param name="targetLocator">   ...Description to be added...</param>
        /// <param name="driver">The browser, that is represented by an <see cref="IWebDriver" /> instance.</param>
        public static Alert Alert([NotNull] this ITargetLocator targetLocator, [NotNull] IWebDriver driver)
        {
            if (targetLocator == null)
            {
                throw new ArgumentNullException(nameof(targetLocator));
            }
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            return(new Alert(driver));
        }
Esempio n. 20
0
 public ZombieFactory(ITimeProvider timeProvider,
                      IEntityLifeManager entityLifeManager,
                      ITargetLocator targetLocator,
                      StateMachineFactory stateMachineFactory,
                      IDoor[] doors,
                      IPool <Zombie> pool)
 {
     _timeProvider        = timeProvider;
     _entityLifeManager   = entityLifeManager;
     _targetLocator       = targetLocator;
     _stateMachineFactory = stateMachineFactory;
     _doors = doors;
     _pool  = pool;
 }
Esempio n. 21
0
        private void SwitchToFrame_(IWebElement frameElement,
                                    ISeleniumFrameCheckTarget frameTarget, Configuration config, List <FrameState> frameStates)
        {
            ITargetLocator switchTo = driver_.SwitchTo();

            switchTo.Frame(frameElement);
            IWebElement rootElement = SeleniumEyes.GetScrollRootElementFromSREContainer(frameTarget, driver_);
            Frame       frame       = driver_.GetFrameChain().Peek();

            frame.ScrollRootElement = rootElement;
            SaveCurrentFrameState_(frameStates, driver_, rootElement);
            TryHideScrollbarsInFrame(config, driver_, rootElement);
            frame.ScrollRootElementInnerBounds = EyesRemoteWebElement.GetClientBoundsWithoutBorders(rootElement, driver_, logger_);
        }
Esempio n. 22
0
        internal Localization(CultureInfo cInfo, ITargetLocator locator)
        {
            _cInfo = cInfo;

            if (locator == null)
            {
                _log.Warning("Locator pass to Localization is null, create default.");
                _locator = LocatorFactory.Create(LocalFilePath.LOCAL_FILE_SCHEME + Runtime.StartupDirectory);
            }
            else
            {
                _locator = locator;
            }
            _locator = _locator.Combine(L10N);
        }
 public static void ParentFrame(Logger logger, ITargetLocator targetLocator, FrameChain frameChainToParent)
 {
     logger.Debug("enter (static)");
     try
     {
         targetLocator.ParentFrame();
     }
     catch
     {
         targetLocator.DefaultContent();
         foreach (Frame frame in frameChainToParent)
         {
             targetLocator.Frame(frame.Reference);
         }
     }
 }
Esempio n. 24
0
 public static void ParentFrame(Logger logger, ITargetLocator targetLocator, FrameChain frameChainToParent)
 {
     logger.Log(TraceLevel.Debug, Stage.General, StageType.Called);
     try
     {
         targetLocator.ParentFrame();
     }
     catch
     {
         targetLocator.DefaultContent();
         foreach (Frame frame in frameChainToParent)
         {
             targetLocator.Frame(frame.Reference);
         }
     }
 }
Esempio n. 25
0
        public void WindowProcess_Demo3()
        {
            IWebDriver driver = new FirefoxDriver();
            //省略部分代码... ...
            var            oldWinHandle = driver.CurrentWindowHandle;
            ITargetLocator locator      = driver.SwitchTo();
            IAlert         winAlert     = locator.Alert();

            winAlert.Accept();                            //确定:Alert , Confirm, Prompt
            winAlert.Dismiss();                           //取消:Confirm, Prompt
            var text = winAlert.Text;                     //获取提示内容:Alert , Confirm, Prompt

            winAlert.SendKeys("input text.");             //输入提示文本:Prompt

            //后续操作... ...
            driver.Quit();
        }
Esempio n. 26
0
        /// <summary>
        /// Uri can be file:/// or clr-ns://, see RexToy.Resources
        /// </summary>
        /// <param name="uri"></param>
        public static void SetResourceBase(string uri)
        {
            if (_locator != null)
            {
                _log.Warning("Localization resource base already set, can't switch.");
                return;
            }

            try
            {
                _locator = LocatorFactory.Create(uri);
            }
            catch
            {
                _log.Warning("Localization build locator with uri [{0}] fail.", uri);
                //Note: will pass null to Localization's constructor. it will handle null.
            }
        }
Esempio n. 27
0
 public FSMZombieBrain(ITimeProvider timeProvider,
                       ITargetLocator targetLocator,
                       StateMachineFactory stateMachineFactory,
                       TargetChaser targetChaser,
                       IAttacker attacker,
                       TimeSpan attackInterval,
                       IDoor[] doors,
                       IMover mover,
                       IPositionDetector positionDetector)
 {
     _timeProvider        = timeProvider;
     _targetLocator       = targetLocator;
     _stateMachineFactory = stateMachineFactory;
     _targetChaser        = targetChaser;
     _attacker            = attacker;
     _attackInterval      = attackInterval;
     _doors            = doors;
     _mover            = mover;
     _positionDetector = positionDetector;
 }
Esempio n. 28
0
        public static IWebDriver Window(ITargetLocator targetLocator, string handle, string browser, bool usingSauce)
        {
            var regularPageNeutralElement         = By.Id("copyright");
            var dayViewBookingPanelNeutralElement = By.XPath("//span[@class='header-title']");

            if (usingSauce && browser.ToLower() == "ie")
            {
                var driver = targetLocator.Window(handle);
                if (driver.FindElement(regularPageNeutralElement).Enabled)
                {
                    driver.FindElement(regularPageNeutralElement).Click();
                }
                else
                {
                    driver.FindElement(dayViewBookingPanelNeutralElement).Click();
                }

                return(driver);
            }
            return(targetLocator.Window(handle));
        }
Esempio n. 29
0
        public IWebDriver FramesDoScroll(FrameChain frameChain)
        {
            logger_.Log(TraceLevel.Debug, Stage.General, StageType.Called);
            ITargetLocator targetLocator = driver_.SwitchTo();

            targetLocator.DefaultContent();
            IPositionProvider scrollProvider = new ScrollPositionProvider(logger_, jsExecutor_, driver_.Eyes.GetCurrentFrameScrollRootElement());

            defaultContentPositionMemento_ = scrollProvider.GetState();
            foreach (Frame frame in frameChain)
            {
                Point frameLocation = frame.Location;
                scrollProvider.SetPosition(frameLocation);
                targetLocator.Frame(frame.Reference);
                Frame newFrame = driver_.GetFrameChain().Peek();
                newFrame.ScrollRootElement            = frame.ScrollRootElement;
                newFrame.ScrollRootElementInnerBounds = frame.ScrollRootElementInnerBounds;
            }

            return(driver_);
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the EventFiringTargetLocator class
 /// </summary>
 /// <param name="driver">The driver that is currently in use</param>
 public EventFiringTargetLocator(EventFiringWebDriver driver)
 {
     this.wrappedLocator = driver.WrappedDriver.SwitchTo();
 }
Esempio n. 31
0
 public static ITargetLocatorWrapper ToWrapper(this ITargetLocator targetLocator)
 {
     return(new TargetLocatorWrapper(targetLocator));
 }
 /// <summary>
 ///     Initializes a new instance of the EventFiringTargetLocator class
 /// </summary>
 /// <param name="driver">The driver that is currently in use</param>
 public EventFiringTargetLocator(EventFiringWebDriver driver)
 {
     parentDriver = driver;
     wrappedLocator = parentDriver.WrappedDriver.SwitchTo();
 }