Selenium Webdriver automated testing development common problems (C# version) VS

1:SeleniumBrowser operation inFirst, generate a Web object.IWebDriver driver = new FirefoxDriver ();/ / open the specified URL address.Driver.Navigate ().GoToUrl (@ @ http://12.99.102.196:9080/corporbank/logon_pro.html);/ / close browserDriver.quit ();In the process of compatibility test of Internet banking browser, when the browser is closed, there will be a dialog box. The solution to this problem is as follows:Public void logout (){System.DiagnosticS.Process[] myProcesses;MyProcesses = System.Diagnostics.Process.GetProcessesByName (“IEXPLORE”);Foreach (System.Diagnostics.Process instance in myProcesses){Instance.Kill ();}}Execute JS script in 2:Selenium/ / need to force driver into JS execution.Device type((IJavaScriptExecutor) driver).ExecuteScript (“JS file name”);Locating page elements in 3:SeleniumDriver.FindEleMent (By.Id (“cp1_btnModify”)).Click ();By.ClassName (className));By.CssSelector (selecto)R);By.Id (ID);By.LinkText (linkText);By.Name (nAME);By.PartialLinkText (linkText);By.TagName (name);By.Xpath (XPAthExpression);3.1 locate and operate according to element ID./ / input string 500001 to the specified text boxDriver.FindElement (By.Id (“amount”)).SendKeYs (“500001”);3.2 locate and operate according to element classname./ / click classname as the button for the specified value.Driver.FindElement (By.ClassName (“Woth”)ErDay)).Click ();3.3 locate and operate according to the linktext of the element.Driver.FindElement (By.LinkText (“select account”)).Click ();Three4 locate and operate according to the Name of the element.Driver.FindElement (By.Name (“quality”)).Perform ();3.5 use CssSelector to locate and operate.StringOrder = “#resultTable.result_table tbody tr.bg1 td.center a”;Driver.FindElement (By.CssSelector (o)Rder)).Click ();3.6 use Xpath to locate and operate elements./ / use multiple attributes to locate elementsDriver.FindElement (By.XPath (“//input[@id=’subm”)It’and @value=’ next step]].Click ();/ / using absolute path location elementsString path = “/html/body/div[4]/div/div/div[2]/”Table/tbody/tr/td/a “;Driver.FindElement (By.Xpath (path)).Click ();The principle of priority is applied to each method:Give priority to ID, name, className, link; next use CssSelector (); finally use Xpath ();Because the Xpath () method has the lowest performance and efficiency.Clears the default content in the text box in 4:Selenium./ / empty text box cleaR ()Driver.FindElement (By.Id (“tranAmtText”)).Clear ();In 5:Selenium, enter the specified string in the specified text box./ / enter in text boxThe specified string sendkeys ()Driver.FindElement (By.Id (“tranAmtText”)).SendKeys (“123456”);Moving cursor to finger in 6:SeleniumFixed elements/ / move cursor to specified element performActions action=new Actions (driver);Action.MoveToElement (Find (By.XPath)(“//input[@id=’submit’and @value=’ determines]”).Perform ();Click button / link in 7:Selenium/ / click the button / link click ()DriVer.FindElement (By.XPath (“//input[@id=’submit’and @value=’ next step”)).Click ();Waiting on page in 8:SeleniumThe elements are loaded to complete./ / wait for page elements to load./ / wait for 100 seconds by default.WebDriverWait wait = new WebDriverWait (driver, TimeSpan.FromSecon)DS (100));/ / wait for the element whose ID attribute is submitButton on the page to load.Wait.Until ((d) => {return WaitForObject (By.Id (“subm”).ItButton ());};Simulate mouse sway in 9:Selenium/ / analog cursor shake movebyoffset ()Actions action = new Actions (driver);Action.MoveByOffset (2, 4);Location of elements in iframe in 10:Selenium5.1: switch focus to iframe with ID fixed value.After entering the page, the cursor is default.In DefaultContent, if you want to locate iframe, you need to switch focus.Driver.SwitchTo ().DefaultContent ();/ / switch focus to mainFrameDriver.SwitchTo ().Frame (“mainFrame”);Note that if you want to switch focus to other iframes after switching focus, you need to return to default content and then switch focus to the specified IFRAOn me.5.2 switch focus to iframe with ID value as dynamic value.Sometimes the ID of the pop-up layer on the page is dynamic, so you need to get all the recorded iframes and place them in an array, then traverse the array to switch focus to the target iframOn e.The following methods:Protected string bizFrameId = string.Empty;Protected string bizId = string.Empty;/ / get the ID value of dynamic iframe.Protected void SetIframeId (){ReadOnlyCollection

Leave a Reply

Your email address will not be published. Required fields are marked *