I Would like to perform tests in safari, using selenium.
Unfortunately, when I try to debug issues using the safari, a notification appears which requires me either disable automation in safari or to quit (attached image).
why I cannot do it as in Chrome & FireFox (for ex: press F12 to see the DOM) ?
Note: I'm using MacOs Catalina with Javascript & Python for selenium
This error message...
...implies that the Safari browser's WebDriver support for developers and automation developers is turned off by default.
Configure Safari to Enable WebDriver Support
As per the documentation in Testing with WebDriver in Safari Safari's WebDriver support for developers is turned off by default. Enabling the WebDriver support depends on your operating system.
In High Sierra and later:
You need to enable safaridriver once.
/usr/bin/safaridriver --enable
If you’re upgrading from a previous macOS release, you may need to use sudo as follows:
sudo /usr/bin/safaridriver --enable
Sierra and earlier:
To make the Develop menu available. Choose Safari > Preferences and on the Advanced tab, select Show Develop menu in menu bar.
Choose Develop > Allow Remote Automation.
Authorize safaridriver to launch the XPC service that hosts the local web server. To permit this, manually run /usr/bin/safaridriver once and follow the authentication prompt.
Unfortunately we don't seem to be able to pause the tests, interact with the browser and then resume the tests afterwards with safaridriver, as we can with geckodriver and chrome webdriver.
The closest option you have is to 'Stop Session' in the pop-up from your screenshot.
From what I can see the 3 options listed are:
Turn off all automation - Stops the test and turns off all the automation settings. This will require you to allow remote automation/enable safaridriver again.
Stop session - this stops the test but leaves the browser open so that you can manually interact with it and use the Web Inspector tools.
Continue session - this closes the pop-up and continues with the test.
So, to summarize for all other (frustrated) developers who come across #Safari and try to automate it.. it is impossible to write automation because of this limitation.
So the options are:
Write in other browser (such as chrome) and verify it works in safari
Manually in other session in safari(manual) locate your locators/paths and then insert to you automation-infra
and to add to complexity - Selenium clicks doesnt work in many places where on chrome/ff/edge DO work.
so, possible solution to that - is to use JS in DOM - but that is also not perfect.
hopefully the situation will improve
This should solve your problem.
warnFromSafari = driver.SwitchTo().Alert();
warnFromSafari.Accept();
Related
I have some Chrome extensions installed and I can use them fine in normal run.
But when I use Selenium to drive Chrome to a page, I see "Chrome is being controlled by automated test software." and I don't have access to those extensions that I have installed. What are some easy ways to have access to the extensions in this kind of scenario? Is there some setting in Chrome perhaps that enables extensions in every mode?
Yes, there are a series of flags you'r need to set up to achieve that.
You can also simply use Selenium-Profiles or undetected-chromedriver for that. Those libraries additionally are undetected by sites like cloudfare and google.
In Chrome for Win/Mac/Linux it is possible to have browser addon scripts running before the user launches the browser and after they shut the last browser window. In Chrome this is done by claiming the background permission - see the Chrome extensions API docs on background. Other browsers don't seem to support this permission. So my questions:
Is this also possible with other browsers (e.g. by using some other permission/API...) and with other operating systems (specifically Android/iOS)?
What is the behavior of this feature across different operating systems? (I have tried it with Chrome on Ubuntu and while Chrome does continue running and the script keeps performing its task, it doesn't automatically start in background after restarting the OS - I guess one would have to manually add an autostart script for that)
What I'm trying to accomplish is something similar as to what as been asked here: Display a Chrome desktop notification every day at specific time. But I want to learn about cross-browser-and-OS-compatibility before putting too much effort into it. Also an outlook for what's going to be possible in the near future would be nice. :)
(I am aware that something like this could be done using push notifications, but I would also like my app to work offline, so that's not an option.)
I am new to programming and my first task, which should be really simple, is to automate a proccess, where I log in in a website with my credentials, I click on some buttons and that is it. I am using Python 3.6 on windows 10.
I am trying to do it using the webbot module, which so far has come really handy but I have one big problem.
The standard browser for webbot is Google Chrome and thus the site always opens with Chrome. I need to open the site with Internet Explorer.
I have set IE as default browser, but nothing changed, Chrome would still open.
I deleted Chrome, but then when I would run the programm nothing would happen.
I checked the init.py file and the drivers folder of the module and I think that this module can only work with chrome.
Is it possible to use IE or does this mean that this package does not support this browser at all?
Which alternatives would you suggest?
Edit: If I am not mistaken Selenium does not support IE11 on windows 10, so that is not an option, unless I am mistaken.
Thanks in advance
There is no support for another browser other than Chrome (as far as the webbot module is concerned).
UPDATED WITH REASONING
Goal: Run chrome web driver in background without showing an app icon in the dock or application bar. FYI: I can already run chrome headless, but I have not been able to hide or not show the chrome icon in my app bar.
Reason: I am building an application that accesses various websites in parallel and I would not like the chrome app icons to display for the synchronous tasks that are taking place. I want to run these tasks in the background.
Current Code with chrome options that will display headless chrome
chrome_options = Options()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1200x600')
driver = webdriver.Chrome(executable_path=executable_text, chrome_options=chrome_options)
Research
list of chrome options: https://peter.sh/experiments/chromium-command-line-switches/
one of many posts explaining how to do headless chrome: Selenium - chrome Driver fail to start in background (without a start-up window)
How can I hide the chromedriver app icons from displaying? Is there a chrome option I can set in addition to setting the 'headless' chrome option? Is this more of an OS setting that needs to be made to run chromedriver in the background? I am successfully able to run multiple chromedrivers in headless mode but it would be nice to NOT show the chrome icons in the dock or application tray similar to how phantomjs does not launch an app icon.
^In the image above those are the chromedrivers that run in headless mode displaying in my dock and ideally for my program I would not even want to display those icons since it is all background processing anyways.
Update (this worked for me to hide the chromedriver icons at least on my Mac):
I was not able to find a Chrome Option to accomplish hiding the chromedriver icons that appear in the dock. However, I was able to edit the Info.plist file for Chrome as part of my program to do the trick (of hiding chromedriver icons) using the LSBackgroundOnly key.
In the Info.plist for Chrome, programmatically, I entered:
<key>LSBackgroundOnly</key>
<string>1</string>
On my Mac using python3 code I used os.system to execute a terminal command using defaults to enter the LSBackgroundOnly key when the program is executing and then at the end of program execution I delete the LSBackgroundOnly key from the Info.plist.
like this:
1)
defaults write /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly -string '1'
2)
defaults delete /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly
AS INFO: This is tricky because your normal chrome app may start up in background mode if you don't add/delete LSBackgroundOnly properly during program execution. In my experience, worst case scenario you may have to manually remove LSBackgroundOnly from the Info.plist file then restart your computer to get Chrome out of background mode.
I remove the LSBackgroundOnly key from the Info.plist file in my program after program execution because the key only needs to be in the file when the chromedrivers are launched. After that I want to be able to use regular Chrome app without issues of it opening in background mode. But, if you understand your program execution and handle your exceptions, this will definitely work to hide the icons correctly and there will be nothing different in using your regular Chrome app.
Happy hacking.
This is not possible using Selenium. I don't really understand why you want to do this. Is there a real purpose, or it's just you don't want it to show? Even if the Chrome app shows on the dock, in headless mode, it works pretty good.
However, if you want your icon to not appear in the dock when opened, then you need to disable it by modifying the Info.plist file for that application.
In your Info.plist for Chrome, add this
<key>LSUIElement</key>
<true/>
This will prevent your app icon from appearing in dock, when working. I found this out a long time ago and this is the post where I saw it.
PS - I have not tested it for Chrome app. Please test at your own peril.
I still haven't been able to find a solution to this problem. We have an application that launches a browser window but the underlying third party addin that we are using doesn't support IE9 yet. I know that I can switch to Browser mode for IE8 by tapping F12 and select this.
Is there a way to control this on the startup in the command line? Cause as it is now we have problem when running the application when it opens new windows and automatically tries to execute this third party addin that is required.
And no we haven't an option, we are forced to use this third party addin but would like to support that installation of IE9 as well.
I don't know if you have any control over the content being rendered in the browser, but if you do, IE lets you use META tags to force the browser into a rendering mode of a specific IE version. More info at MSDN right here
Also, further down the page there are instructions on how to set up your web server to tell IE which mode to use when it's requesting the page. (If that is of any use to you)
Unfortunately all information I can find on the subject (and I did a comprehensive search for my own project) indicates that there is no such option, or at least not in the general release
of IE.
Here's Microsoft's "official"
list of currently supported IE command line options