{"id":13990485,"url":"https://github.com/sergueik/powershell_selenium","last_synced_at":"2025-07-30T13:31:48.383Z","repository":{"id":29510679,"uuid":"33048947","full_name":"sergueik/powershell_selenium","owner":"sergueik","description":"Split selenium part of powershell_ui_samples git repository","archived":false,"fork":false,"pushed_at":"2025-07-28T04:15:14.000Z","size":95768,"stargazers_count":38,"open_issues_count":5,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-28T06:19:24.831Z","etag":null,"topics":["csharp","powershell","selenium","selenium-webdriver"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergueik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-03-28T20:24:57.000Z","updated_at":"2025-07-28T04:15:18.000Z","dependencies_parsed_at":"2023-02-15T13:16:08.194Z","dependency_job_id":"8f895c48-8eef-497a-9f96-0241e19c0d3d","html_url":"https://github.com/sergueik/powershell_selenium","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sergueik/powershell_selenium","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fpowershell_selenium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fpowershell_selenium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fpowershell_selenium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fpowershell_selenium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergueik","download_url":"https://codeload.github.com/sergueik/powershell_selenium/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fpowershell_selenium/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267875484,"owners_count":24158780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","powershell","selenium","selenium-webdriver"],"created_at":"2024-08-09T13:02:46.996Z","updated_at":"2025-07-30T13:31:46.449Z","avatar_url":"https://github.com/sergueik.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"### Info\n\nCollection of scripts and modules for controling with the browser via\n[.net Selenium driver managed assembly](https://www.nuget.org/packages/Selenium.WebDriver)\npackage from Powershell\nThe project is illustrating various typical Selenium tasks in a problem-solution fashion.\n\nThe code is using well known syntax of invoking public\n[C# Selenium API methods](https://seleniumhq.github.io/selenium/docs/api/dotnet/)\nfrom Powershell in a transparent fashion:\n```c#\n\nusing NUnit.Framework;\nusing OpenQA.Selenium;\nusing OpenQA.Selenium.Chrome;\nusing OpenQA.Selenium.Interactions;\n\nIWebDriver driver = new ChromeDriver();\nint timeout = 10;\nWebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout);\ndriver.Navigate().GoToUrl(base_url);\nActions actions = new Actions(driver);\nstring selector = \"div.dropdown.open ul.dropdown-menu\";\nwait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(selector)));\nIWebElement element = driver.FindElement(By.CssSelector(selector));\nactions.MoveToElement(element).Click().Build().Perform();\nstring script = \"arguments[0].setAttribute('style', arguments[1]);\";\nObject result = ((IJavaScriptExecutor)driver).ExecuteScript(script, element);\n```\nbecomes\n```powershell\n\n[OpenQA.Selenium.Remote.WebDriver]$driver = new-object OpenQA.Selenium.Chrome.ChromeDriver\n$timeout = 10\n[OpenQA.Selenium.Support.UI.WebDriverWait]$wait = new-object OpenQA.Selenium.Support.UI.WebDriverWait ($driver,[System.TimeSpan]::FromSeconds($timeout))\n[OpenQA.Selenium.Interactions.Actions]$actions = new-object OpenQA.Selenium.Interactions.Actions ($driver)\n$selector = 'div.dropdown.open ul.dropdown-menu'\n$wait.Until([OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists([OpenQA.Selenium.By]::CssSelector($selector)))\n$element = $driver.FindElement([OpenQA.Selenium.By]::CssSelector($selector))\n$script = 'arguments[0].setAttribute(\"style\", arguments[1]);'\n$result = (([OpenQA.Selenium.IJavaScriptExecutor]$driver).ExecuteScript($script,$element, ('color: {0}; border: 4px solid {0};' -f $color ))).ToString()\n```\nNaturally, Powershell version is somehow quite more verbose therefore the common / shared functionality is put into `selenium_common.psm1` and `page_navigation_common.psm1` modules.\n\n![Developing Selenium Scripts in Powershell ISE](https://raw.githubusercontent.com/sergueik/powershell_selenium/master/screenshots/55a.png)\n\n### Basic Usage:\n\nTo run a Selenium test in Powershell, start with the following script:\n```powershell\n\nparam(\n  [string]$browser = '',\n  [string]$base_url = 'https://www.indiegogo.com/explore#',\n  [switch]$grid,\n  [switch]$pause\n)\n  import-module -Name ('{0}/{1}' -f '.', 'selenium_utils.psd1')\n\n  # create WebDriver object\n  if ([bool]$PSBoundParameters['grid'].IsPresent) {\n    $selenium = launch_selenium -browser $browser -grid\n  } else {\n    $selenium = launch_selenium -browser $browser\n  }\n  set_timeouts ([ref]$selenium)\n  $selenium.Navigate().GoToUrl($base_url)\n  # create Actions object\n  $actions = new-object OpenQA.Selenium.Interactions.Actions($selenium)\n\n  # create WebDriverWait object\n  $wait = new-object OpenQA.Selenium.Support.UI.WebDriverWait ($selenium,[System.TimeSpan]::FromSeconds(1))\n  $wait.PollingInterval = 100\n\n  # iterate over ingiegogo campains ...\n\n  $project_card_tagname = 'discoverable-card'\n  $project_card_title_selector = 'div[class*=\"discoverableCard-title\"]'\n\n  [object[]]$project_card_elements = $selenium.FindElements([OpenQA.Selenium.By]::TagName($project_card_tagname))\n\n  Write-Output ('{0} project card found' -f $project_card_elements.count)\n  $project_card_elements | ForEach-Object {\n    $project_card_element = $_\n    [void]$actions.MoveToElement([OpenQA.Selenium.IWebElement]$project_card_element).Build().Perform()\n    write-output $project_card_element.Text\n    write-output '----'\n    highlight ([ref]$selenium) ([ref]$project_card_element)\n    [object]$project_card_title = $project_card_element.FindElement([OpenQA.Selenium.By]::CssSelector($project_card_title_selector))\n    flash ([ref]$selenium) ([ref]$project_card_title)\n    # continue test\n  }\n\n  # Cleanup\n  cleanup ([ref]$selenium)\n```\nRun the script with the option:\n```powershell\n. ./test_script.ps1 -browser chrome\n```\n\n### Prerequisites\nPowershell relies on C# Selenium Client API library for interaction with the browser, Nunit for assertions and log4net for logging.\nThus needs those asemblies need to be available in the directory `$env:SHARED_ASSEMBLIES_PATH`\n(default used in this project is `c:\\java\\selenium\\csharp\\sharedassemblies`):\n```\nlog4net.dll\nnunit.core.dll\nnunit.framework.dll\nnunit.mocks.dll\nWebDriver.dll\nWebDriver.Support.dll\n```\n\nDownload past versions download links on nuget:\n  * [Selenium.WebDriver v. 2.53.1](https://www.nuget.org/packages/Selenium.WebDriver/2.53.1)\n  * [Selenium.Support v. 2.53.1](https://www.nuget.org/packages/Selenium.Support/2.53.1)\n\ne.g. with\n```powershell\n$ProgressPreference = 'silentlyContinue' ;\npushd $env:TEMP\n$download_api_href = 'https://www.nuget.org/api/v2/package/Selenium.Support/2.53.1' ;\n$output_file = 'Selenium.Support.nupkg' ;\nInvoke-WebRequest -uri $download_api_href -OutFile $output_file ;\nAdd-Type -assembly 'system.io.compression.filesystem'\n\n[IO.Compression.ZipFile]::ExtractToDirectory(\"${env:TEMP}\\${output_file}\", $env:TEMP)\ncopy-item -path .\\lib\\net35\\WebDriver.Support.dll -destination $shared_assemblies_path\n```\nNOTE: you will have to close the powershell window that has been running Powershell Selenium scripts to avoid __The process cannot access the file because it is being used by another process__ error.\n\nThere is no strict enforcement to use Selenium 2.x - the Selenium 3.x libraries work as well. In particular, headless mode can be enabled by passing the `-headless` flag to the `launch_selenium` helper method.OB\n\nThe Selenium jars and drivers are loaded from `$env:SELENIUM_DRIVERS_PATH` or from `$env:SELENIUM_PATH` (whichever is found set first) or from `c:\\java\\selenium` by default:\n```\nchromedriver.exe\ngeckodriver.exe\nIEDriverServer.exe\nhub.cmd\nhub.json\nhub.log4j.properties\nlog4j-1.2.17.jar\nnode.cmd\nnode.json\nnode.log4j.properties\nnode.xml\nselenium-server-standalone-2.53.1.jar\n```\nThe recent versions of the drivers are found in\n\n  * [chromedriver](https://chromedriver.storage.gooeapis.com/)\n  * [edgedriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)\n  * [geckodriver](https://api.github.com/repos/mozilla/geckodriver/releases)\n  * [iedriver](https://selenium-release.storage.googleapis.com/)\n\nThe Java runtime is supposed to be installed under `c:\\java`:\n```\nc:\\java\\jdk1.7.0_79\nc:\\java\\jre7\nc:\\java\\selenium\n```\n\nThe .net Selenium assemblies can be loaded from alternative location / withspeciic build versos via the following code:\n\n```powershell\n$shared_assemblies = @{\n  'WebDriver.dll'         = '3.13.0';\n  'WebDriver.Support.dll' = '3.13.0';\n  'nunit.core.dll'        = $null;\n  'nunit.framework.dll'   = '2.6.3';\n}\n\n$MODULE_NAME = 'selenium_utils.psd1'\nImport-Module -Name ('{0}/{1}' -f '.', $MODULE_NAME)\n\n$custom_shared_assemblies_path = 'c:\\users\\sergueik\\Downloads'\n\nload_shared_assemblies_with_versions -path $custom_shared_assemblies_path -shared_assemblies $shared_assemblies\n\n\n```\nthis has to be done before initializing the browser\n```poweshell\n  $selenium = launch_selenium -browser $browser\n```\n\nThe phantomjs is supposed to be installed under `C:\\tools\\phantomjs-2.0.0\\bin`.\n\nThe mockup of Selenium grid is launched on the local host TCP port `4444` via `hub.cmd`, `node.cmd`:\t\n```cmd\nset SELENIUM_VERSION=2.53.1\nset JAVA_VERSION=1.7.0_79\nset JAVA_HOME=c:\\java\\jdk%JAVA_VERSION%\nPATH=%JAVA_HOME%\\bin;%PATH%;c:\\Program Files\\Mozilla Firefox\njava -XX:MaxPermSize=1028M -Xmn128M -jar selenium-server-standalone-%SELENIUM_VERSION%.jar -port %HTTP_PORT% -role hub\n```\n\nAlternatively one may specify the `$hub_host`, `$hub_port` arguments and a `$use_remote_driver` switch\nto make script connect to Selenium through `Remote Driver` class with `http://${hub_host}:${hub_port}/wd/hub`\nBy default hub and node are launched locally on port `4444` when `$use_remote_driver` is set.\n\n### Note:\n\nUsing raw .Net method calls from Powershell looks rather verbosely:\n```powershell\n(New-Object OpenQA.Selenium.Interactions.Actions ($selenium)).MoveToElement([OpenQA.Selenium.IWebElement]$element).Click().Build().Perform()\n[OpenQA.Selenium.Support.UI.SelectElement]$select_element = New-Object OpenQA.Selenium.Support.UI.SelectElement ($selenium.FindElement([OpenQA.Selenium.By]::CssSelector($css_selector)))\n[NUnit.Framework.StringAssert]::AreEqualIgnoringCase($expected_text, $element.Text)\n\n```\nand naturally this leads to a big number of helper methods written in this project.\n\nThe common functionality for locating elements, changing the element visual appearance on the page\nis mostly refactored into the modules `selenium_common.psm1` and `page_navigation_common.psm1`\nOlder scripts contained the same functionality inline, few scripts still do, for some reason.\nThe Powershell named function arguments \"calling convention\" is used in the project e.g:\n\n```powershell\n[string]$css_selector = 'input#mainSearch'\n[object]$element = find_element -css_selector $css_selector\nhighlight ([ref]$selenium) ([ref]$element)\n```\nor\n```powershell\nhighlight -element ([ref]$element) -color 'green' -selenium_ref ([ref]$selenium)\n```\n\n* [PhantomJS development halted and project to be archived](https://groups.google.com/forum/#!topic/selenium-developers/YMuCPtX6dyg)\n* [Groovy REPL](https://groups.google.com/forum/#!topic/selenium-developers/Z44lwr95Kzs)\n* [old Knowledge Vault article about Selenium WebDriver with Powershell](http://knowledgevault-sharing.blogspot.com/2017/05/selenium-webdriver-with-powershell.html)\n\n![Selenium Execution Pipeline](https://raw.githubusercontent.com/sergueik/powershell_selenium/master/screenshots/selenium_execution_pipeline.png)\n\n### Author\n[Serguei Kouzmine](kouzmine_serguei@yahoo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergueik%2Fpowershell_selenium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergueik%2Fpowershell_selenium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergueik%2Fpowershell_selenium/lists"}