Selenium & Powershell

on Monday, March 25, 2019

Selenium is sort of a pseudo-industry standard for UI browser testing. There are others tools available (like cypress.io), but Selenium is a really well known / popular. And that’s why it’s ported or made available into so many other languages. It’s made available in Powershell using the Selenium module by Adam Driscoll (he was the creator of the Powershell Tools for Visual Studio).

The documentation in the github readme.md is short, but its all you really need to get started. But, you quickly start to run into the same problems the rest of the Selenium community runs into (Selenium – How to wait until page is completely loaded [duplicate], Selenium wait for Ajax content to load – universal approach).

So, here’s a quick function to help wait for a particular element on a page to load.

And, here’s a sample Pester test using the function.

3 comments:

mavericksevmont said...

Hi Steven, great post! Thanks, this is great. I am also looking at Adam's module, I have the opposite problem, I want the .click() method to timeout faster, I don't want it to wait, it's set by default on 60 seconds, I want it to timeout in 10 seconds or less so it can keep running the script faster, for example, I tried this without luck:
$Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromSeconds(10)

This is the error for the timeout:

Exception calling "Click" with "0" argument(s): "The HTTP request to the
remote WebDriver server for URL http://localhost:58845/session/8ca4cf95c0b630cf
b6a809559f8d7133/element/0.7697548073205163-1/click timed out after 60
seconds."

Do you have any clue on how I can set it up to throw the exception faster than 60 seconds?

smaglio81 said...

I'm afraid I don't know how to do that. I think you're a lot farther ahead on how to do that than I am. I wish you the best of luck!

mavericksevmont said...

No! Prob! Couldn't fix it, but worked around it by wrapping certain bits to run async within a PowerShell background job,that did the trick for me. Thank you for the reply!

Post a Comment


Creative Commons License
This site uses Alex Gorbatchev's SyntaxHighlighter, and hosted by herdingcode.com's Jon Galloway.