|
1 | 1 | <#
|
2 |
| -.VERSION - 0.1 |
| 2 | +.VERSION - 0.2 |
3 | 3 |
|
4 | 4 | .DESCRIPTION
|
5 | 5 | This is an example script that will show you how to use the Selenium driver to preform a simple google search.
|
6 | 6 | Using this example script you will learn the basic usage of the Selenium powershell module.
|
7 | 7 | Each comment line will explain the line that will come after it so you can follow it in a step by step fashion.
|
8 | 8 | #>
|
9 | 9 |
|
10 |
| -# The line below will Import-Module Selenium if it fails it will display the installation command |
11 |
| -try{Import-Module -Name Selenium -ErrorAction Stop}catch{Write-Host 'Importing the Selenium module failed. Please install it using the following command: Install-Module Selenium'} |
| 10 | +# The line below will Import-Module Selenium if it fails it will display the installation command and stop the script. |
| 11 | +try{Import-Module -Name Selenium -ErrorAction Stop}catch{Write-Host 'Importing the Selenium module failed. Please install it using the following command: Install-Module Selenium';break} |
12 | 12 |
|
13 | 13 | # Start the Selenium Chrome Driver
|
14 | 14 | $Driver = Start-SeChrome
|
15 | 15 |
|
16 |
| -# Next we will check if the driver is running and if it's not running we will show a message. if the driver is running we will run the commands inside the if statment |
| 16 | +# Next we will check if the driver is running and if it's not running we will show a message. If the driver is running we will run the commands inside the if statment. |
17 | 17 | if($Driver){
|
18 | 18 | # Now that we verified that the driver is running we can start doing cool things with it.
|
19 | 19 |
|
@@ -48,20 +48,20 @@ if($Driver){
|
48 | 48 | # Now that we can see all the keys we can send send some keys to the SearchBoxElement
|
49 | 49 | Send-SeKeys -Element $SearchBoxElement -Keys 'Powershell-Selenium'
|
50 | 50 |
|
51 |
| - # You can send special key strokes to the textbox, you should use the Selenium Keys enum. For example, if we wanted to send an enter key stroke, you could do it like this |
| 51 | + # You can send special key strokes to the SearchBoxElement, you should use the Selenium Keys enum. For example, if we wanted to send an enter key stroke, you could do it like this |
52 | 52 | Send-SeKeys -Element $SearchBoxElement -Keys ([OpenQA.Selenium.Keys]::Enter)
|
53 | 53 |
|
54 | 54 | # When working with dynamic websites, it’s often necessary to wait awhile for elements to appear on the page. By default, Selenium won’t wait and you’ll receive $null from Find-SeElement because the element isn’t there yet. There are a couple ways to work around this.
|
55 | 55 | # The first is to use the Wait-SeElementExists cmdlet to wait for the existence of an element in the document.
|
56 | 56 | # The Wait-SeElementExists will also return the element once it is found so you can use in order to wait and then find elements on the page.
|
57 | 57 |
|
58 |
| - #This command will wait for the img elements for 10 seconds and then return it to you or time out if the element wasn't found on. |
| 58 | + # This command will wait for the img elements for 10 seconds and then return it to you or time out if the element wasn't found on. |
59 | 59 | $ImageElements = Wait-SeElementExists -Driver $Driver -TagName 'img' -Timeout 10
|
60 | 60 |
|
61 |
| - # Once we have the image element we can simulate a mouse click on it using the Invoke-SeClick command |
| 61 | + # Once we have the image element we can simulate a mouse click on it using the Invoke-SeClick command. |
62 | 62 | Invoke-SeClick -Driver $Driver -Element $ImageElements
|
63 | 63 |
|
64 |
| - # Once we are done with the web driver and we finished with all our testing/automation we can release the driver by running the Stop-SeDriver command |
| 64 | + # Once we are done with the web driver and we finished with all our testing/automation we can release the driver by running the Stop-SeDriver command. |
65 | 65 | Stop-SeDriver -Driver $Driver
|
66 | 66 | }
|
67 | 67 | # if the driver is not running we will enter the script block in the else section and display a message
|
|
0 commit comments