My goal is the following : take a screenshot of a web page (opened with selenium) where the panel (toolbar) is present in order to see the time on it. This should be scheduled automatically.
I have : a linux VM and a windows computer
What I did :
Script myscript.ps1
Import-Module Selenium
Import-Module Scraping
# $url = "https://sanctionssearch.ofac.treas.gov/"
$url = "https://www.google.com/"
$driver = Start-SeChrome -Quiet -Incognito -Maximized
Enter-SeUrl $url -Driver $driver
waitdriver $driver
#############################################################################
# Capturing a screenshot
#############################################################################
scrot test.png
#############################################################################
$driver.Close()
$driver.Quit()
When I run this directly from my linux virtual machine, I get what I want (web window and panel):
But my goal is to schedule it, so I used an ssh connection from windows with the following command:
$commande='cd myfolderpath; export PATH=$PATH:/snap/bin;'+ "xvfb-run -a nice -n20 pwsh myscript.ps1"
ssh -i "${env:\userprofile}\.ssh\spinlinux2_key.pem" linuxvm#52.8.3.2 $commande
But now I don't get the toolbar in capture but only the web page:
Is there any other way to proceed? It can also be directly scheduled from windows without going through the linux machine.
Thanks for all your answers.
Related
We've been using Selenium to automate some browser testing in Internet Explorer. On Windows 7 32-bit it works fine. However we're testing it on Windows 10 64-bit and it fails miserably.
Sometimes the browser doesn't even launch
If i change the driver versions, i can get the browser to launch but it hangs on the first page
The issue is only present when I use ForceCreateProcessApi. However I need to use ForceCreateProcessApi in order to use BrowserCommandLineArguments!
The exception is: The HTTP request to the remote WebDriver server for URL http://localhost:16639/session timed out after 60 seconds.
Here is the PowerShell code i use:
$seleniumOptions = New-Object OpenQA.Selenium.IE.InternetExplorerOptions
$seleniumOptions.InitialBrowserUrl = $SiteUrl
$seleniumOptions.ForceCreateProcessApi = $true
$seleniumOptions.BrowserCommandLineArguments = "-k"
$seleniumOptions.IgnoreZoomLevel = $true
New-Variable -Name IEDS -Value ([OpenQA.Selenium.IE.InternetExplorerDriverService]) -Force
$defaultservice = $IEDS::CreateDefaultService()
$seleniumDriver = New-Object OpenQA.Selenium.IE.InternetExplorerDriver -ArgumentList #($defaultservice, $seleniumOptions)
I've tried the following versions (x86 and x64 versions), and none of them work:
2.25.3
3.141
3.9.0
Can anybody advise on how to make this work? I've made sure that TabProcGrowth etc is set according to the documentation.
Thanks.
Try to use a 3.150.1 32-bit driver.
I'm not sure how it looks on PS - but I'm able to run IE with this driver config.
ie: { version: "3.150.1", arch: "ia32" }
Also I have a key for iexplore.exe here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
from this config link
Should return only list of hosts available in the SCVMM not it's details.
[https://learn.microsoft.com/en-us/powershell/module/virtualmachinemanager/get-scvmhost?view=systemcenter-ps-2019][1]
With this script you gonna get a list of the hosts, and the details of the first one.
To run this script you gonna need the VMM powershell module, that is only available where the VMM console is installed.
## Import VMM module
Import-Module VirtualMachineManager
## Get the VMM server
Get-VMMServer "vmm.contoso.com" | out-null
## Get all hosts managed by the VMM server.
$Hosts = Get-SCVMHost
## Print the hosts list
Write-Host $Hosts
## With this line you gonna print all the attributes of the first host:
$Hosts[0]
I developed several scripts in Powershell to automate the configuration of machines where I work, streamlining and avoiding the hard work of manually configuring a huge amount of stations. Basically they use disable UAC, autologon, and Task Scheduler.
Image: https://i.stack.imgur.com/pkuDl.png
The biggest problem is the use of the Fortinet Firewall that asks for authentication via browser, since much of the application uses files for installation that are on the server via SMB, it is necessary to do this authentication, because without it it is not possible for the algorithm to authenticate to the server, causing it to fail on the course.
Image: https://i.stack.imgur.com/bqZAR.png
Page URL: https://authenticator.mpms.mp.br/caplogin/?login&post=http://10.111.147.1:1000/fgtauth&magic=0202e294cb1c7073&usermac=10:e7:c6:c5:c3:61&apmac=00:00:00:00:00:00&apip=10.111.147.1&userip=10.111.147.22&ssid=PGJ-BANCADA&apname=FGT2KE3917900027&bssid=00:00:00:00:00:00&device_type=windows-pc
However, by testing this through Selenium it even authenticates, but after the computer restarts and runs the next script, it asks for authentication again.
Follow the code that I made to authenticate in Fortnet, followed after the login, to make a request in the globo.com site
############################################
######## Enable Fortinet Firewall ##########
############################################
$YourURL = "https://authenticator.mpms.mp.br/"
# Adds the path for ChromeDriver.exe to the environmental variable
$env:PATH += ";C:\Util\PSL\"
# Adding Selenium's .NET assembly (dll) to access it's classes in this PowerShell session
Add-Type -Path "C:\Util\PSL\WebDriver.dll"
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver.Capabilities.BrowserName
# Browse to the specified website
$ChromeDriver.Navigate().GoToURL($YourURL)
# Methods to find the input textbox for google search and then to type something in it
$ChromeDriver.FindElementByName("username").SendKeys("username")
$ChromeDriver.FindElementByName("password").SendKeys("password")
$ChromeDriver.FindElementsByClassName("submit").Submit()
#### New page #####
$YourURL = "https://www.globo.com/"
$ChromeDriver.Navigate().GoToURL($YourURL)
Function Stop-ChromeDriver {Get-Process -Name chromedriver -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue}
# Close selenium browser session method
$ChromeDriver.Close()
# End ChromeDriver process method
$ChromeDriver.Quit()
# Function to make double sure the Chromedriver process is finito (double-tap!)
Stop-ChromeDriver
When we do this manually, the next steps will run normally, which by my conclusion makes the Selenium driver not really the Google Chrome browser, but rather its own one, which means that it does not recognize authentication. .
The question that remains is: Is it possible to add this option in the script so that we can authenticate to Fortinet Web and thus avoid manual steps and automate our work? I wish I could perform this task for Powershell, but I'm available with another alternative.
Thank you!
Why not use vbs in PowerShell` to send required authorizations?
$wshell = New-Object -ComObject wscript.shell; $obj = New-Object -com Wscript.Shell;
$wshell.AppActivate('Chrome');
pathping 127.0.0.1 -n -q 1 -p 300 >$null
$obj.SendKeys('paulogoncalves');
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys("{TAB}")
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('senhasecreta')
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('{ENTER}');```
I have been trying to get this to work via a game control panel TCAdmin.
$ModPg1 = Invoke-WebRequest "http://steamcommunity.com/sharedfiles/filedetails/?id=731604991"
$ModVer1 = ($ModPg1.ParsedHtml.getElementsByTagName('div') | Where{ $_.className -eq 'detailsStatRight' } ).innerText | Select -Last 1
If I run this cmdlet via a program like TCAdmin (or task scheduler), I get the following error....
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
Explorer is installed, and set up. The script works just fine if I run it manually.
My guess is there is a way to get TCAdmin to run the scripts the same way I would as a windows User.
Cant find a way nearly as simple to scrape the info 'm looking for.
As for this...
get TCAdmin to run the scripts the same way I would as a windows User.
For any app to run as a user, that users profile must be used on the host where the code is to be run. You cannot natively run PoSH on a host as another user context. This is not a PoSH issue, it is a Windows User Principal security boundary. There are tools that let you do this. For example SysInternal PSExec and AutoIT. Yet as stated that error is pretty specific. The user profile for Internet Explorer has not been created and that only happens when you use IE at least once.
So, as Adam points, out, use the setting the error message states to use or use your code to start IE at least once.
$SomeUrl = 'https://stackoverflow.com'
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($SomeUrl)
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1 } # Wait for IE to settle.
Again, if trying to run this in the context of another user, the two above tools will get you there, but you still have to fire up IE to have a profile for it.
I am using below PS script which will download Zip file from Nexus to Jenkins slave windows server.(Working as expected)
My another task is to copy files from Jenkins windows server location to another windows server location.When I add this script in jenkins job i dont see any output nor errors. Please help me copy files which are zipped from Jenkins windows server to another windows server.
$ApplicationName="safenetws"
$clnt = new-object System.Net.WebClient
$url = "http://localhost:8081/$($env:VERSION)/$ApplicationName-$($env:VERSION).zip"
$file = "D:\Packages\$ApplicationName-$($env:VERSION).zip"
$clnt.DownloadFile($url,$file)
$session = new-pssession -computername $($env:SERVER) -credential $($env:PASSWORD)
$shell_app=new-object -com shell.application
stop-WebSite -Name "SampleApp"
$items = $shell_app.NameSpace("D:\Packages\$ApplicationName-$($env:VERSION).zip\Content\C_C\Jenkins\workspace\Call\obj\Release\Package\PackageTmp\").Items()
$shell_app.NameSpace("D:\AppCode\wwwroot\SampleApp").CopyHere($items)
start-WebSite -Name "SampleApp"
You can use any file transfer servers, like FTP, I have used FTP for the same requirement, By using ftp plugin in Jenkins, you can configure the source (Jenkins work space) to destination (other windows server). when the build is running it will copy the code from one location to other.