Close chrome depending on link in address bar - google-chrome

Let me start with i have very little scripting / programming knowledge :)
My problem is, I have a web page for dashboard in call center that runs off projectors. The webpage is on internal web server.
The web page times out randomly and creates error.
I need to close Chrome (or Firefox) when a web page address changes to error page eg: from localsite.local/page to localsite.local/error
I used Auto-IT- Au3Record and SciTe to record mouse clicks of when the page times out.
This works fine on some PC's but not all. Is there a generic script I could run,
so I don't have to record mouse clicks on all PC's.
current working script
#Region v3.3.9.5 KeyboardLayout=00000809
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '00000809' Then
MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & #CRLF & '(00000809->' & $aResult[1] & ')')
EndIf
EndFunc
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
_AU3RecordSetup()
_WinWaitActivate("Website.com/site/Main_Dash_Reporting.aspx - Google Chrome","")
MouseClick("left",1342,14,1)
_WinWaitActivate("Program Manager","")
MouseClick("left",282,746,1)
_WinWaitActivate("Website.com/site/Dash_Viewer.aspx?DashID=5200&RevNum=null - Google Chrome","")
MouseMove(702,311)
MouseDown("left")
MouseMove(707,310)
MouseUp("left")
#EndRegion

Internet Explorer is the programmers tool.
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
If window.locationname="Scripts" then window.quit
Next
This is a vbscript. For historical reasons it includes both Explorer and IE windows.
Another property is window.locationURL.

Related

Opening Chrome from Automator with unicode in URL fails

I'm using Automator to open a link in Chrome based on on some selected text:
on run {input, parameters}
set kanji to input as string
set link to "https://jisho.org/search/" & kanji
tell application "Google Chrome"
open location link
end tell
end run
This works fine when the input text is ASCII, and a new Chrome tab opens at the URL, but nothing happens (and no error when put in a "try" block) when the input text is kanji (eg 漢字). Open "Safari" always works correctly, so this looks like a Chrome thing?
Chrome 91.0.4472.164, macOS 11.3.
Thanks for any insights!
Update: Thanks row and gurkensaas.
I ended up with this working version:
on run {input, parameters}
set kanji to input as string
set link to "https://jisho.org/search/" & kanji
try
tell application "Google Chrome"
tell its window 1
set URL of (make new tab) to link
end tell
end tell
on error errMsg number errorNumber
display dialog "Error occurred: " & errorNumber as text
end try
end run

chrome window acts like an iframe (when running with disabled web security)

I launch chrome with --disable-web-security flag for testing purposes", then my html page is loaded(http://my.page.com/), and opens a new tab using var wnd1 = window.open('https://other.domain.com'). When the new page is loaded (in a new tab), I can execute some javascript on the new window object, for instance: wnd1.document.querySelector(".class1 p"). So far everything makes sense.
Then again, I open a page from different domain: var wnd2 = window.open('https://different.domain2.com'), and try to access its document with javascript code: wnd2.document, but now I get an error that looks related to iframes: "Uncaught DOMException: Blocked a frame with origin "http://my.page.com" from accessing a cross-origin frame.
at :1:4"
This error occurs only with specific domains (in contrast to "regular" domains - msn.com, google.com, etc., which I can open and execute JS code on). Any header that makes it act like an iframe? some other protection methods?

How to open new window instead of new tab in chrome using webdriver?

In order to automate my test application, I need to open few links in a new window instead of tab. Keep this in mind that I am not opening the links in new tab explicitly, it is my web application which automatically lands user in the new tab after clicking on the link.
Why do I want to do this?
Because running the tests on chrome browser closes the main tab and keeps open the newly opened tab. Which ultimately fails the tests.So ultimate intention is to open the new window instead of tab and handle it properly using driver.getWindowHandles().
What have I done so far?
I tried to find some kind of capability setting or profile in Chrome which automatically opens the links in a new window which are supposed to be open in a tab.But did not find any convincing solution most of the suggestions are CTRL+CLICK ON THE LINK.
I'm not a guru of web-design, but I can suggest following scenario:
// Get required page
// Excecute below JavaScript with JavaScriptExecutor
var reference = document.querySelector('a#someID').getAttribute('href'); // You can use your specific CSS Selector instead of "a#someID"
document.querySelector('a#someID').setAttribute("onclick", "window.open('" + reference + "', '', 'width=800,height=600')")
document.querySelector('a#someID').removeAttribute('href')
// Find target link
// Click on it
This code should allow you to make changes in HTML source code of target web-element to force its opening in new browser window.
Note that with this code element's appearance on page will be changed until page refresh
P.S. You didn't mentioned your programming language, so there is no complete implementation... However, this is Python implementation example:
from selenium import webdriver as web
dr = web.Chrome()
dr.get('https://login.live.com/login.srf?&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1%26realm%3dlogin.live.com')
dr.execute_script("""
var reference = document.querySelector('a#ftrTerms').getAttribute('href');
document.querySelector('a#ftrTerms').setAttribute("onclick", "window.open('" + reference + "', '', 'width=800,height=600')")
document.querySelector('a#ftrTerms').removeAttribute('href')
""")
link = dr.find_element_by_id('ftrTerms')
link.click()
Well, in the absence of any flag/setting/capability in Chrome browser which opens the links in a new window instead of the new tab I used a Chrome Extension for that via WebDriver.
Why did I do that?
Because my tests are running fine on Firefox and I have no idea how many WebElements are there in the suite which gets open in new tab in Chrome browser. The suite is also very huge so doing any changes in its core page class may break the all the tests.In addition to that, changing code at an element level will be very time-consuming and most importantly not a generic solution.
What did I do?
I used a chrome extension New Tab New Window, which opens all the new tabs into a new window.
Downloaded the CRX file of this extension using an extension Get CRX.
Set the CRX file as a capability of Chrome.
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("pathOfCRXFile"));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
So above will convert all the new tabs into a new window.So whenever the driver clicks on any link which further opens in a new tab will get opened into the new window.

Windows Phone Store - its possible to disable application switcher screen screenshot

I have disabled the functionality to take a screenshot from my app using:
ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
But I would like to hide all the content before the application is suspended/sent to background so the thumbnail appearing in the recent apps or application switcher screen does not show any confidential information.
Have tried to hide content on the onSuspend and Visibility_Changed events, but i think the sceenshot is taken just the moment the user press the Home Button (the one with the Windows logo).
Do you know any way of disabling that feature?
Subscribing to the WindowActivated event might be worth a try. The name is misleading as it will be launched on (any kind of) deactivation as well; which is what you want. I use it to save information on exit scenarios such as Home Button press but have not tested whether you could do a quick redraw or not.
Protected Overrides Async Sub OnLaunched(e As LaunchActivatedEventArgs)
''Stuff
AddHandler Window.Current.Activated, AddressOf WindowActivated
''Stuff
End Sub
Private Sub WindowActivated(sender As Object, e As Windows.UI.Core.WindowActivatedEventArgs)
If e.WindowActivationState = Windows.UI.Core.CoreWindowActivationState.Deactivated Then
''Hide your confidential visuals here
End If
End Sub

Watir hangs after Chrome asks "Do you want google to save your password"

I'm having Watir login and do some stuff on the next page.
This works fine on Firefox, but chrome loads the :
"Do you want google to save your password" dialog
which makes Watir hang. Running the script from irb, I'm noticing
that at that point I'm losing access to the browser object.
Clicking "Never for this site" or "Save Password" doesn't seem to work either
since it seems that every time that webdriver loads chrome, it loads in on a new
session.
Any ideas?
If you go to Configuration -> Options -> Personal Stuff there's a check box for "Never offer to save passwords" that may change the setting for the program, rather than just the instance you're currently interacting with.
I had a similar problem (everything works in Firefox but not Chrome) and maybe this will help. Do you have any regular expressions in your code after the page loads?
In my code I modified this statement:
#browser.text_field(:id => /txtfield/).wait_until_present
to this:
#browser.text_field(:id => 'longform_txtfield').wait_until_present
That is to say that I removed the /txtfield/ regular expression and replaced it with the full id name of 'longform_txtfield'. Obviously you and I have very different code but try experimenting with commenting out certain lines after the page load to see what may be responsible. It just might turn out not to be the Password Manager after all!
Cheers!
I know this is may be an old question but I did stumble upon this question while looking for a solution using Watir-webdriver.
The below snippet will open a Chrome browser with the password manager disabled i.e. the "save your password" dialog will not pop-up;
profile = Selenium::WebDriver::Chrome::Profile.new
profile['profile.password_manager_enabled'] = false
#browser = Watir::Browser.new :chrome, profile: profile