in order to kill a process, I usually use
Process.GetProcessesByName("process name")(0).Kill()
This does not work if I want to close Chrome, using "Chrome" as the process name.
I know that Google Chrome runs with more than one process, at least that's what my task manager shows, so I guess this is the problem: because there are several processes called "Chrome", vb.net is unable to close them all or just closes one which doesn't lead to Chrome closing.
What code could I use instead, to close ALL processes called "Chrome"?
Try using this
Dim i As Integer = Ubound(Process.GetProcessesByName("Chrome.exe"))
For x As Integer = i To 0 Step -1
Process.GetProcessesByName("Chrome.exe")(x) .Kill()
Next
Related
I'm using MSAccess VBA with Selenium VBA, Chromedriver
I am able to get to a website, login, find the button to click to start download, and get that download to save to the location I want.
I want to track the progress.
I have opened a new Chrome window (tab) and navigated to chrome:\\downloads\ and switched my driver window to that window.
I've used the following code I found on stack overflow, in a loop to monitor the progress.
downloadPercentage = wd.ExecuteScript("return document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('#progress').value")
It returns this error ...cannot return properties of null...
My download is present on the page. I can get the file name.
When I open the developer tab on the downloads page and enter the same query selector path into the console I get the same thing. It returns null.
If I manually (or maybe even using VBA haven't tried) click the button for a second download, then all of a sudden that same code returns a value of 100. (It may catch it at a lower percent. The download is too fast for me to catch that in debug mode.)
What would cause the selector to not be present for one download, but then present for the next?
Here's the code that's in question.
Function getDownloadedFileName(wd as ChromeDriver) As String
Dim startTime As Date
'I'm using this method because opening a second ChromeDriver instance and going to the chrome://downloads/ page returns a clean slate (no downloads) and this method works for me.
wd.ExecuteScript ("window.open()")
wd.SwitchToNextWindow
wd.Get "chrome://downloads/"
startTime = Now()
Dim downloadPercentage As Integer
Do While DateDiff("s", startTime, Now()) < 120 And downloadPercentage < 100
'This is the line that returns the Javascript error ... Cannot read properties of null ...
downloadPercentage = wd.ExecuteScript("return document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('#progress').value")
If (downloadPercentage = 100) Then
getDownLoadedFileName = wd.ExecuteScript("return document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('div#content #file-link').text")
Exit Do
End If
Loop
wd.SwitchToPreviousWindow
End Function
I'll appreciate any help on this. Thanks!
i just want to get the final url from a redirect.
I can read this with url = GC2.Url but the end takes a long time to load completely.
how do i get it now that as soon as i call the link with my 2nd selenium instance the webite doesn't wait for it and uses "none". but as soon as i close my 2nd instance again and continue with my first instant the normal time is used again.
i have found some approaches here: Don't wait for a page to load using Selenium in Python
approximate example:
Set GC = New Selenium.ChromeDriver
Set GC2 = New Selenium.ChromeDriver
for c = 1 to 100
GC.Get link(c)
Set Elements = GC.FindElementsByCss("p.TITLE a[href]")
For Each Element In Elements
ReDim Preserve links(a) As String
links(a) = Element.Attribute("href") 'geht auch innerHTML/href usw.
a = a + 1
GC2.Get links(a) ' this here should not wait so long
redict(a) = GC2.Url
GC2.Close
Next Element
Try to work in Headless mode, it might be faster. In this mode the browser doesn't open and everything happens with the "eyes closed", everything is virtual.
I'm working on a VBA program to help automate a task using UI Automation, but I've run into an issue where the window of the program I'm trying to control does not show up as a child of the Root Element (desktop).
It's my understanding that all elements are children/descendants of the desktop element, so why it's not showing up is puzzling. Here is the code I'm using to see all the children of the Desktop element:
Sub test_get_windows()
Dim oAutomation As New CUIAutomation
Dim oDesktop As UIAutomationClient.IUIAutomationElement
Dim oCondition As UIAutomationClient.IUIAutomationCondition
Dim oChilds As UIAutomationClient.IUIAutomationElementArray
Dim i As Integer
Set oDesktop = oAutomation.GetRootElement
Set oCondition = oAutomation.CreateTrueCondition
Set oChilds = oDesktop.FindAll(TreeScope_Children, oCondition)
For i = 0 To oChilds.Length - 1
Debug.Print oChilds.GetElement(i).CurrentName
Next i
End Sub
I see everything except the window I'm trying to interact with. I tried the code on another computer, and I'm able to see the window.
Computer where it doesn't work:
Computer where it does work:
The AcSELerator Quickset window does not show up on the first computer but it does on the second, so I don't think it's a problem with the application. Both computers have the same version installed and are running Windows 10 Enterprise. Any ideas on what the issue could be or any troubleshooting steps I can try?
The window doesn't have to be minimized. Try veryfyng that. That's what was happening to me. Similar case and Similar routine.
I am using Selenium Webdriver to load a specific feature from an application, a rich text editor (actually a custom release of CKEditor) and the code below works perfectly for that... except that I would like to release Selenium objects (and geckodriver.exe/marionnette black cmd window) since the desired page was loaded. But either .Close(), .Quit() or .Dispose() methods will wipe out the Firefox window as well...
Is there a way to dismiss Selenium Webdriver and keep Firefox running by its own?
Thank you very much
Private Sub LoadResource()
Dim FFD As New OpenQA.Selenium.Firefox.FirefoxDriver()
'Set timeout of 60 seconds for steps to complete successfully
Dim WDW As New OpenQA.Selenium.Support.UI.WebDriverWait(FFD, TimeSpan.FromSeconds(60))
'navigate to login page
FFD.Navigate.GoToUrl("https://www.myapplication.com/login")
'Wait until application loads main page (this means login was successful)
WDW.Until(Function() FFD.Url = "https://www.myapplication.com/")
'Load built-in rich text editor Rich text
FFD.Navigate.GoToUrl("https://www.myapplication.com/editor?document=1080199")
'Wait for successful loading of the editor page
WDW.Until(Function() FFD.Url = "https://www.myapplication.com/editor?document=1080199")
'That's all.
'here I'd like to release Firefox to keep running and get rid of WebDriver's objects and resources, if possible.
End Sub
This is based on Kirhgoph's comment and seems to work well:
Private Sub LoadResource()
Dim FFD As New OpenQA.Selenium.Firefox.FirefoxDriver()
Dim GDP As Process = Process.GetProcessesByName("geckodriver").Last
Dim WDW As New OpenQA.Selenium.Support.UI.WebDriverWait(FFD, TimeSpan.FromSeconds(60))
FFD.Navigate.GoToUrl("https://www.myapplication.com/login")
WDW.Until(Function() FFD.Url = "https://www.myapplication.com/")
FFD.Navigate.GoToUrl("https://my.application.com/editor?document=1080199")
WDW.Until(Function() FFD.Url = "https://www.myapplication.com/editor?document=1080199")
GDP.CloseMainWindow()
GDP.WaitForExit()
FFD.Quit()
End Sub
I'm developing a service in VB.net. The problem is if more than 1 IE windows are running, whenever i end a iexplorer process it doesn't close the corresponding IE window. i.e. if 4 windows are running i try to end 3 processes(That arrived after first process) one by one none of them closes but when i end that particular process(That arrived first) that is somehow holding all processes all Internet Explorers close down.
What i'm trying to do is i want commandline args of IE processes and i get args of first IE but after that i get this:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" "http://ksnap.bpweb.com/webtop/drl/versionLabel/CURRENT"
Thats what i want but when second IE process arrives i get this:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" SCODEF:424 CREDAT:79874"
and for all next arriving IE processes i get args :i.e. SCODEF:xxxx CREDAT:xxxx (xxxx represent digits)
I don't think you should be doing this by killing processes. You should be use internet explorer automation.
In c#:
using SHDocVw;
using mshtml;
private static IEnumerable<InternetExplorer> GetInternetExplorers()
{
ShellWindows shellWindows = new ShellWindowsClass();
List<InternetExplorer> allExplorers = shellWindows.Cast<InternetExplorer>().ToList();
IEnumerable<InternetExplorer> internetExplorers = allExplorers.Where( ie => Path.GetFileNameWithoutExtension( ie.FullName ).ToLower() == "iexplore" );
return internetExplorers;
}
References:
MSHTML - Microsoft HTML Object Library
Interop.SHDocVw.dll - Microsoft Internet Controls
Look into this a bit more, you should be able to find and close open tabs.