How to Steer Frame in Selenium

Switch to frame Select a frame by its (zero-based) index driver.switchTo().frame(int index) Select a frame by its name or ID driver.switchTo().frame(String nameOrId) Select a frame by WebElement driver.switchTo().frame(WebElement frameElement) Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged driver.switchTo().parentFrame(); Selects either the first frame on the page, or the main document when a page contains iframes driver.

Reusing Existing Browser Session in Selenium

During script development or debugging in selenium, if we can attach the code to an existing browser session, it will make things easier. Here is how to do it with Chrome. Open chrome with remote debugging port "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 Start chrome driver WebDriver wdriver =null; ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", ""); driver = new ChromeDriver(options);

FindElements By JQuery locator

Lots of websites use JQuery, and JQuery selector has more features than Css locator, such as contains etc. So try to use Javascript Executor to execute JQuery selector and return the WebElements. public static IEnumerable<IWebElement> FindElementsByJQuery(ISearchContext context, string locator) { var jsContext = context as IJavaScriptExecutor; if (jsContext != null) { var jObjects = (Dictionary<string,object>)jsContext.ExecuteScript(string.Format("return jQuery(\"{0}\")", locator)); foreach (var o in jObjects) { if (!(o.Value is IWebElement)) { continue; } yield return (IWebElement) o.

Selenium locator extension

In Selenium, there are multiple locator functions, such as By.CssSelector By.XPath By.Id By.Name …… In my case, I would like to use different format, which I can call one method instead of so many, it would be easier to store the locator information somewhere else. The locator format would be ByMethod = selector to Find, for example: css=input[value=’clear’][type=button] So an extension method was created for this, here is the code snippet.