Skip to content

Instantly share code, notes, and snippets.

# assume "element" is a properly found WebElement instance,
# "wait" is a properly constructed WebDriverWait instance,
# and "driver is the proper WebDriver instance.
original_handle = driver.current_window_handle
original_handle_list = driver.window_handles
element.click()
wait.until(expected_conditions.new_window_is_opened(original_handles))
new_handle_list = driver.window_handles
window_handle_difference = list(set(new_handle_list) - set(original_handle_list))
new_window_handle = window_handle_difference[0]
public bool IsVisible
{
get
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(3));
ActiveCompaniesGrid = wait.Until(d => d.FindElement(ActiveCompaniesGridId));
return ActiveCompaniesGrid.Displayed;
}
@jimevans
jimevans / setup-selenium-dev-env.cmd
Last active April 8, 2020 03:23
Setup of a Selenium Development Environment in Windows (batch and PowerShell versions)
REM Tested and confirmed to work on a newly-installed Windows 10 Professional Build 1909
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowAllTrustedApps" /d "1"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
powershell -NoProfile -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
choco install -y git
choco install -y openjdk11
choco install -y python
choco install -y visualstudio2019community --params "--add Microsoft.VisualStudio.Workload.ManagedDesktop;includeRecommended --add Microsoft.Net.Component.4.6.2.TargetingPack --add Microsoft.Net.Component.4.7.1.TargetingPack --add Micr
def _library_impl(ctx):
providers = {}
stdrefs = [ctx.attr._stdrefs] if ctx.attr.include_stdrefs else []
for tfm in ctx.attr.target_frameworks:
providers[tfm] = AssemblyAction(
ctx.actions,
name = ctx.attr.name,
additionalfiles = ctx.files.additionalfiles,
@jimevans
jimevans / gist:f566d6946f05038021fd08d19788f9c5
Created September 25, 2019 17:18
C++ save base64-encoded image as file
void SaveSnapshot(const std::string& base64_encoded_image) {
std::vector<BYTE> buffer(base64_encoded_image.size());
int len = buffer.size();
::Base64Decode(base64_encoded_image.c_str(),
base64_encoded_image.size(),
&buffer[0],
&len);
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, len);
LPVOID pImage = ::GlobalLock(hMem);
@jimevans
jimevans / gist:65bf2a5c4bd7382bd6200df1da4933df
Created September 25, 2019 16:20
use of diagnostics script engine to execute script in IE driver refactor
std::wstring script = L"";
//script.append(L"browser.result = browser.executeScript(\"");
//script.append(L"(function() { ");
//script.append(script_source);
//script.append(L" }).apply(window, [])");
//script.append(L"\");");
//script.append(L"\nexternal.sendMessage('debug', JSON.stringify(browser.webdriver.known));");
//script.append(L"\nexternal.sendMessage('script', JSON.stringify(browser.result));");
//script.append(L"browser.scriptContext = dom.getCrossSiteWindow(browser.document.parentWindow, browser.document.parentWindow);");
script.append(L"browser.context = browser.executeScript(\"window;\"");
@jimevans
jimevans / BrowserStackChromeOptions.cs
Created September 9, 2019 21:07
BrowserStack type-safe options creator for .NET
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the Chrome-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackChromeOptions
{
private static readonly string DriverVersionOptionName = "driver";
@jimevans
jimevans / Example.cs
Created September 9, 2019 17:34
SauceLabs type-safe options creator
SauceLabsSessionOptions sauceOptions = new SauceLabsSessionOptions();
sauceOptions.UserName = "username";
sauceOptions.AccessKey = "accessKey";
ChromeOptions options = new ChromeOptions();
options.AddAdditionalOption(SauceLabsSessionOptions.SauceOptionsOptionName, sauceOptions.ToDictionary());
IWebDriver driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"), options);
@jimevans
jimevans / 4.cs
Last active September 6, 2019 18:49
Dictionary<string, object> browserStackOptions = new Dictionary<string, object>();
browserStackOptions.Add("os", "Windows");
browserStackOptions.Add("osVersion", "10");
browserStackOptions.Add("resolution", "1024x768");
browserStackOptions.Add("userName", "barancev");
browserStackOptions.Add("accessKey", "xxx");
browserStackOptions.Add("sessionName", "Bstack-[C_sharp] Sample Test");
ChromeOptions options = new ChromeOptions();
options.BrowserVersion = "62.0";
options.AddAdditionalOption("bstack:options", browserStackOptions);
public class ExtendedFirefoxDriver : FirefoxDriver
{
// NOTE: Add constructor overloads to support the instantiations your tests require.
public ExtendedFirefoxDriver(string servicePath, FirefoxOptions options) : base(servicePath, options)
{
this.CommandExecutor.CommandInfoRepository.TryAddCommand("installAddOn", new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/moz/addon/install"));
}
public void InstallAddOnFromFile(string addOnFileToInstall)
{