need to update https://www.seleniumhq.org/about/platforms.jsp to mention Powershell support

22 views
Skip to first unread message

Serguei Kouzmine

unread,
Oct 8, 2018, 5:53:11 PM10/8/18
to Selenium Developers
Hello

I am developer of one of the projects using Powerhsll to control? 



Selenium via its .net client assembly using a wll known ability of Powrshell claling public methods of a managed assembly  like e.g.



sing NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;

IWebDriver driver = new ChromeDriver();
int timeout = 10;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout);
driver.Navigate().GoToUrl(base_url);
Actions actions = new Actions(driver);
string selector = "div.dropdown.open ul.dropdown-menu";
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(selector)));
IWebElement element = driver.FindElement(By.CssSelector(selector));
actions.MoveToElement(element).Click().Build().Perform();
string script = "arguments[0].setAttribute('style', arguments[1]);";
Object result = ((IJavaScriptExecutor)driver).ExecuteScript(script, element);

converted into Powershell "code"


[OpenQA.Selenium.Remote.WebDriver]$driver = new-object OpenQA.Selenium.Chrome.ChromeDriver

$timeout = 10
[OpenQA.Selenium.Support.UI.WebDriverWait]$wait = new-object OpenQA.Selenium.Support.UI.WebDriverWait ($driver,[System.TimeSpan]::FromSeconds($timeout))
[OpenQA.Selenium.Interactions.Actions]$actions = new-object OpenQA.Selenium.Interactions.Actions ($driver)
$selector = 'div.dropdown.open ul.dropdown-menu'
$wait.Until([OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists([OpenQA.Selenium.By]::CssSelector($selector)))
$element = $driver.FindElement([OpenQA.Selenium.By]::CssSelector($selector))
$script = 'arguments[0].setAttribute("style", arguments[1]);'
$result = (([OpenQA.Selenium.IJavaScriptExecutor]$driver).ExecuteScript($script,$element, ('color: {0}; border: 4px solid {0};' -f $color ))).ToString()

The project exists for quite some time. It offers very similar functionality as the underlying  .Net client.

I has not tried it under .net/core and unix OS'es but about to soon.

I think Selenium users will benefit from knowing that it is possible to control Selenium from Powershell too.

Thanks

Serguei Kouzmine

Reply all
Reply to author
Forward
0 new messages